import 'package:flutter_test/flutter_test.dart'; import 'package:melo/services/sync_merge.dart'; void main() { group('zuPushendeFavoriten', () { test('leer gegen leer ergibt nichts', () { expect( zuPushendeFavoriten( lokaleFavoriten: const {}, cloudIdVon: const {}, amServer: const {}, ), isEmpty, ); }); test('was der Server noch nicht hat, geht hoch', () { expect( zuPushendeFavoriten( lokaleFavoriten: const {'s1', 's2'}, cloudIdVon: const {'s1': 'c1', 's2': 'c2'}, amServer: const {'c1'}, ), ['c2'], ); }); test('Titel ohne cloudId kennt der Server nicht und bleiben liegen', () { // Lokal-only: der Titel wurde nie hochgeladen, es gibt nichts zu melden. expect( zuPushendeFavoriten( lokaleFavoriten: const {'s1'}, cloudIdVon: const {}, amServer: const {}, ), isEmpty, ); }); test('was beidseitig steht, wird nicht erneut gepusht', () { expect( zuPushendeFavoriten( lokaleFavoriten: const {'s1'}, cloudIdVon: const {'s1': 'c1'}, amServer: const {'c1'}, ), isEmpty, ); }); test('der Deckel begrenzt einen Lauf', () { final viele = {for (var i = 0; i < 250; i++) 's$i'}; final zuordnung = {for (var i = 0; i < 250; i++) 's$i': 'c$i'}; final offen = zuPushendeFavoriten( lokaleFavoriten: viele, cloudIdVon: zuordnung, amServer: const {}, ); expect(offen, hasLength(maxFavoritenPushes)); }); }); group('lokalZuSetzendeFavoriten', () { test('disjunkte Mengen: der Server-Favorit kommt lokal dazu', () { expect( lokalZuSetzendeFavoriten( amServer: const {'c9'}, songIdVonCloudId: const {'c9': 's9'}, lokaleFavoriten: const {}, ), ['s9'], ); }); test('eine lokal unauflösbare cloudId wird übersprungen, nicht gelöscht', () { // Der Titel ist hier (noch) nicht vorhanden. Ein Favorit ohne Song wäre // unsichtbar, würde aber ewig mitgeschleppt. expect( lokalZuSetzendeFavoriten( amServer: const {'c9'}, songIdVonCloudId: const {}, lokaleFavoriten: const {}, ), isEmpty, ); }); test('was lokal schon Favorit ist, wird nicht noch einmal gesetzt', () { expect( lokalZuSetzendeFavoriten( amServer: const {'c1'}, songIdVonCloudId: const {'c1': 's1'}, lokaleFavoriten: const {'s1'}, ), isEmpty, ); }); }); group('berichtFaellig', () { final jetzt = DateTime(2026, 8, 27, 12); test('ohne vorherigen Erfolg nicht fällig', () { // Neuinstallation: „Willkommen zurück! 325 neue Songs" wäre Unsinn. expect(berichtFaellig(null, jetzt), isFalse); }); test('unter 24 Stunden nicht fällig', () { expect(berichtFaellig(jetzt.subtract(const Duration(hours: 23)), jetzt), isFalse); }); test('ab 24 Stunden fällig', () { expect(berichtFaellig(jetzt.subtract(const Duration(hours: 24)), jetzt), isTrue); expect(berichtFaellig(jetzt.subtract(const Duration(days: 3)), jetzt), isTrue); }); }); }