import 'package:drift/drift.dart' show Migrator; import 'package:drift/native.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:melo/library/database.dart'; void main() { test('Bestandsdaten überleben die neue Spalte', () async { final db = MeloDb(NativeDatabase.memory()); addTearDown(db.close); // Den Stand von Schema 10 nachbauen: Tabelle ohne cloud_id, mit Daten. await db.customStatement('DROP TABLE playlist_songs'); await db.customStatement('DROP TABLE playlists'); await db.customStatement( 'CREATE TABLE playlists (' 'id TEXT NOT NULL, ' 'name TEXT NOT NULL, ' 'description TEXT NULL, ' 'created_at_ms INTEGER NOT NULL, ' 'updated_at_ms INTEGER NOT NULL, ' 'deleted INTEGER NOT NULL DEFAULT 0, ' 'PRIMARY KEY (id))', ); await db.customStatement( "INSERT INTO playlists (id, name, created_at_ms, updated_at_ms) " "VALUES ('alt-1', 'Road Trip', 0, 0)", ); await Migrator(db).addColumn(db.playlists, db.playlists.cloudId); final rows = await db.select(db.playlists).get(); expect(rows.single.name, 'Road Trip'); expect(rows.single.cloudId, isNull); }); test('setPlaylistCloudId merkt sich die Server-ID', () async { final db = MeloDb(NativeDatabase.memory()); addTearDown(db.close); final id = await db.createPlaylist('Mix'); await db.setPlaylistCloudId(id, '42'); expect((await db.playlistById(id))!.cloudId, '42'); }); test('countPlaylists zählt auch Grabsteine', () async { final db = MeloDb(NativeDatabase.memory()); addTearDown(db.close); final id = await db.createPlaylist('Mix'); await db.deletePlaylist(id); // Sonst hielte die Wiederherstellung ein Gerät, auf dem der Nutzer alle // Playlisten gelöscht hat, für eine Neuinstallation. expect(await db.countPlaylists(), 1); }); }