feat(services): add PlaylistService, wire into app providers

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Hermes (Server)
2026-08-18 15:28:24 +02:00
co-authored by Claude Haiku 4.5
parent 449fe4ce76
commit 92f565b1d4
3 changed files with 87 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:melo/library/database.dart';
import 'package:melo/library/playlist_service.dart';
void main() {
late MeloDb db;
late PlaylistService service;
setUp(() {
db = MeloDb(NativeDatabase.memory());
service = PlaylistService(db);
});
tearDown(() async => db.close());
test('createPlaylist delegates to db and notifies listeners', () async {
var notified = false;
service.addListener(() => notified = true);
await service.createPlaylist('Road Trip');
final playlists = await db.watchPlaylists().first;
expect(playlists.length, 1);
expect(playlists.first.name, 'Road Trip');
expect(notified, true);
});
test('toggleFavorite delegates to db and notifies listeners', () async {
await db.into(db.songs).insert(SongsCompanion.insert(
id: 'song-1', path: '/a.mp3', title: 'A', dateAddedMs: 0, updatedAtMs: 0,
));
var notified = false;
service.addListener(() => notified = true);
await service.toggleFavorite('song-1');
expect(await db.watchIsFavorite('song-1').first, true);
expect(notified, true);
});
}