cyberhybridhub/server/test/question_source_mix_test.dart
nathanAndrinoid 4459852f83
Some checks failed
Admin portal tests / test (push) Has been cancelled
spelling
2026-06-05 03:22:35 +00:00

90 lines
2.5 KiB
Dart

import 'package:cyberhybridhub_server/question_source_mix.dart';
import 'package:cyberhybridhub_server/questions_db.dart';
import 'package:test/test.dart';
void main() {
group('QuestionSourceMix.pickNextSourceId', () {
test('picks highest share when nothing delivered yet', () {
expect(
QuestionSourceMix.pickNextSourceId(
effectiveMixPercent: <String, int>{
'market_history': 70,
'spelling': 30,
},
deliveredCounts: <String, int>{},
),
'market_history',
);
});
test('picks spelling when market is ahead of target mix', () {
expect(
QuestionSourceMix.pickNextSourceId(
effectiveMixPercent: <String, int>{
'market_history': 50,
'spelling': 50,
},
deliveredCounts: <String, int>{
'market_history': 4,
'spelling': 0,
},
),
'spelling',
);
});
test('picks market when spelling is ahead of target mix', () {
expect(
QuestionSourceMix.pickNextSourceId(
effectiveMixPercent: <String, int>{
'market_history': 70,
'spelling': 30,
},
deliveredCounts: <String, int>{
'market_history': 1,
'spelling': 3,
},
),
'market_history',
);
});
});
group('QuestionSourceMix.orderUnansweredByPreferredSource', () {
test('puts preferred source first preserving FIFO within source', () {
final List<Map<String, dynamic>> ordered =
QuestionSourceMix.orderUnansweredByPreferredSource(
<Map<String, dynamic>>[
<String, dynamic>{
'id': 'm1',
'sourceTag': 'market_history:prospective',
'createdAt': '2026-01-01T00:00:00Z',
},
<String, dynamic>{
'id': 's1',
'sourceTag': 'spelling:word_quiz',
'pipelineKey': 'spelling',
'createdAt': '2026-01-02T00:00:00Z',
},
<String, dynamic>{
'id': 'm2',
'sourceTag': 'market_history:prospective',
'createdAt': '2026-01-03T00:00:00Z',
},
],
preferredSourceId: 'spelling',
);
expect(ordered.map((Map<String, dynamic> r) => r['id']).toList(), <String>[
's1',
'm1',
'm2',
]);
expect(
QuestionsDb.resolveSourceId(ordered.first),
'spelling',
);
});
});
}