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: { 'market_history': 70, 'spelling': 30, }, deliveredCounts: {}, ), 'market_history', ); }); test('picks spelling when market is ahead of target mix', () { expect( QuestionSourceMix.pickNextSourceId( effectiveMixPercent: { 'market_history': 50, 'spelling': 50, }, deliveredCounts: { 'market_history': 4, 'spelling': 0, }, ), 'spelling', ); }); test('picks market when spelling is ahead of target mix', () { expect( QuestionSourceMix.pickNextSourceId( effectiveMixPercent: { 'market_history': 70, 'spelling': 30, }, deliveredCounts: { 'market_history': 1, 'spelling': 3, }, ), 'market_history', ); }); }); group('QuestionSourceMix.orderUnansweredByPreferredSource', () { test('puts preferred source first preserving FIFO within source', () { final List> ordered = QuestionSourceMix.orderUnansweredByPreferredSource( >[ { 'id': 'm1', 'sourceTag': 'market_history:prospective', 'createdAt': '2026-01-01T00:00:00Z', }, { 'id': 's1', 'sourceTag': 'spelling:word_quiz', 'pipelineKey': 'spelling', 'createdAt': '2026-01-02T00:00:00Z', }, { 'id': 'm2', 'sourceTag': 'market_history:prospective', 'createdAt': '2026-01-03T00:00:00Z', }, ], preferredSourceId: 'spelling', ); expect(ordered.map((Map r) => r['id']).toList(), [ 's1', 'm1', 'm2', ]); expect( QuestionsDb.resolveSourceId(ordered.first), 'spelling', ); }); }); }