52 lines
1.8 KiB
Dart
52 lines
1.8 KiB
Dart
import 'package:drift/drift.dart';
|
|
import 'package:drift/native.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:melo/library/database.dart';
|
|
|
|
void main() {
|
|
late MeloDb db;
|
|
setUp(() => db = MeloDb(NativeDatabase.memory()));
|
|
tearDown(() => db.close());
|
|
|
|
SongsCompanion song(String id, String path, String title, {String? artist}) =>
|
|
SongsCompanion.insert(
|
|
id: id,
|
|
path: path,
|
|
title: title,
|
|
artist: Value(artist),
|
|
dateAddedMs: 1,
|
|
updatedAtMs: 1,
|
|
);
|
|
|
|
test('upsert + watchSongs sortiert nach Titel', () async {
|
|
await db.upsertSongs([song('1', '/a.mp3', 'Beta'), song('2', '/b.mp3', 'Alpha')]);
|
|
final songs = await db.watchSongs().first;
|
|
expect(songs.map((s) => s.title), ['Alpha', 'Beta']);
|
|
});
|
|
|
|
test('Re-upsert gleicher id erzeugt kein Duplikat, aktualisiert', () async {
|
|
await db.upsertSongs([song('1', '/a.mp3', 'Alt')]);
|
|
await db.upsertSongs([song('1', '/a.mp3', 'Neu')]);
|
|
final songs = await db.watchSongs().first;
|
|
expect(songs.length, 1);
|
|
expect(songs.first.title, 'Neu');
|
|
});
|
|
|
|
test('searchSongs findet über Titel und Künstler', () async {
|
|
await db.upsertSongs([
|
|
song('1', '/a.mp3', 'Nachtpuls', artist: 'Rotklang'),
|
|
song('2', '/b.mp3', 'Taglicht', artist: 'Beatzwei'),
|
|
]);
|
|
expect((await db.searchSongs('nacht').first).length, 1);
|
|
expect((await db.searchSongs('rotklang').first).length, 1);
|
|
expect((await db.searchSongs('xyz').first).length, 0);
|
|
});
|
|
|
|
test('markMissing setzt Tombstone für fehlende Pfade', () async {
|
|
await db.upsertSongs([song('1', '/a.mp3', 'A'), song('2', '/b.mp3', 'B')]);
|
|
await db.markMissing(['/a.mp3'], 2); // /b.mp3 fehlt jetzt
|
|
final songs = await db.watchSongs().first;
|
|
expect(songs.map((s) => s.path), ['/a.mp3']);
|
|
});
|
|
}
|