63 lines
1.7 KiB
Dart
63 lines
1.7 KiB
Dart
@Tags(<String>['integration', 'postgres'])
|
|
library;
|
|
|
|
import 'package:cyberhybridhub_server/question_dispatcher.dart';
|
|
import 'package:cyberhybridhub_server/questions_db.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import '../helpers/test_db.dart';
|
|
|
|
void main() {
|
|
TestDb? testDb;
|
|
|
|
setUpAll(() async {
|
|
testDb = await TestDb.open();
|
|
});
|
|
|
|
tearDown(() async {
|
|
if (testDb != null) {
|
|
await testDb!.truncateTradingTables();
|
|
}
|
|
});
|
|
|
|
tearDownAll(() async {
|
|
await testDb?.close();
|
|
});
|
|
|
|
test('listPanelQuestions excludes market when market_history disabled', () async {
|
|
if (testDb == null) {
|
|
markTestSkipped('Set DATABASE_URL or TEST_DATABASE_URL for integration tests');
|
|
return;
|
|
}
|
|
|
|
const String uid = 'spelling-only-panel-uid';
|
|
await testDb!.seedUser(uid);
|
|
await testDb!.questionSourcePreferencesDb.save(
|
|
uid,
|
|
<Map<String, dynamic>>[
|
|
<String, dynamic>{'id': 'market_history', 'enabled': false, 'ratio': 0},
|
|
<String, dynamic>{'id': 'spelling', 'enabled': true, 'ratio': 100},
|
|
],
|
|
);
|
|
|
|
await testDb!.questionsDb.createQuestion(
|
|
assignedUserId: uid,
|
|
questionText: 'Stale market question',
|
|
correctAnswer: 10,
|
|
sourceTag: 'market_history:prospective',
|
|
pipelineKey: 'trading',
|
|
);
|
|
|
|
final QuestionDispatcher dispatcher = testDb!.questionDispatcher();
|
|
final List<Map<String, dynamic>> panel =
|
|
await dispatcher.listPanelQuestions(uid);
|
|
|
|
expect(panel, isNotEmpty);
|
|
for (final Map<String, dynamic> payload in panel) {
|
|
expect(payload['sourceId'], isNot('market_history'));
|
|
}
|
|
expect(panel.first['sourceId'], 'spelling');
|
|
expect(panel.first['presentation'], 'spelling_word');
|
|
});
|
|
}
|