sync the rest of the source models

refactor music download/storage to avoid re-download during reset
add palylist to test server setup
This commit is contained in:
austinried
2025-11-07 15:20:38 +09:00
parent 0e6acbed0f
commit 0c80dbdba5
13 changed files with 451 additions and 149 deletions

View File

@@ -76,4 +76,215 @@ void main() {
isNotNull,
);
});
test('syncAlbums', () async {
await db
.into(db.albums)
.insert(
AlbumsCompanion.insert(
sourceId: sourceId,
id: 'shouldBeDeleted',
name: 'shouldBeDeleted',
created: DateTime.now(),
),
);
await db
.into(db.albums)
.insert(
AlbumsCompanion.insert(
sourceId: sourceIdOther,
id: 'shouldBeKept',
name: 'shouldBeKept',
created: DateTime.now(),
),
);
await sync.syncAlbums();
expect(
await db.managers.albums
.filter((f) => f.sourceId.equals(sourceId))
.count(),
equals(3),
);
expect(
await db.managers.albums
.filter((f) => f.id.equals('shouldBeDeleted'))
.getSingleOrNull(),
isNull,
);
expect(
await db.managers.albums
.filter((f) => f.id.equals('shouldBeKept'))
.getSingleOrNull(),
isNotNull,
);
});
test('syncSongs', () async {
await db
.into(db.songs)
.insert(
SongsCompanion.insert(
sourceId: sourceId,
id: 'shouldBeDeleted',
title: 'shouldBeDeleted',
),
);
await db
.into(db.songs)
.insert(
SongsCompanion.insert(
sourceId: sourceIdOther,
id: 'shouldBeKept',
title: 'shouldBeKept',
),
);
await sync.syncSongs();
expect(
await db.managers.songs
.filter((f) => f.sourceId.equals(sourceId))
.count(),
equals(20),
);
expect(
await db.managers.songs
.filter((f) => f.id.equals('shouldBeDeleted'))
.getSingleOrNull(),
isNull,
);
expect(
await db.managers.songs
.filter((f) => f.id.equals('shouldBeKept'))
.getSingleOrNull(),
isNotNull,
);
});
test('syncPlaylists', () async {
await db
.into(db.playlists)
.insert(
PlaylistsCompanion.insert(
sourceId: sourceId,
id: 'shouldBeDeleted',
name: 'shouldBeDeleted',
created: DateTime.now(),
changed: DateTime.now(),
),
);
await db
.into(db.playlists)
.insert(
PlaylistsCompanion.insert(
sourceId: sourceIdOther,
id: 'shouldBeKept',
name: 'shouldBeKept',
created: DateTime.now(),
changed: DateTime.now(),
),
);
await sync.syncPlaylists();
expect(
await db.managers.playlists
.filter((f) => f.sourceId.equals(sourceId))
.count(),
equals(1),
);
expect(
await db.managers.playlists
.filter((f) => f.id.equals('shouldBeDeleted'))
.getSingleOrNull(),
isNull,
);
expect(
await db.managers.playlists
.filter((f) => f.id.equals('shouldBeKept'))
.getSingleOrNull(),
isNotNull,
);
});
test('syncPlaylistSongs', () async {
await db
.into(db.playlistSongs)
.insert(
PlaylistSongsCompanion.insert(
sourceId: sourceId,
playlistId: 'shouldBeDeleted',
songId: 'shouldBeDeleted',
position: 1,
),
);
await db
.into(db.playlistSongs)
.insert(
PlaylistSongsCompanion.insert(
sourceId: sourceIdOther,
playlistId: 'shouldBeKept',
songId: 'shouldBeKept',
position: 1,
),
);
await sync.syncPlaylistSongs();
expect(
await db.managers.playlistSongs
.filter((f) => f.sourceId.equals(sourceId))
.count(),
equals(7),
);
expect(
await db.managers.playlistSongs
.filter((f) => f.playlistId.equals('shouldBeDeleted'))
.getSingleOrNull(),
isNull,
);
expect(
await db.managers.playlistSongs
.filter((f) => f.playlistId.equals('shouldBeKept'))
.getSingleOrNull(),
isNotNull,
);
});
test('syncPlaylistSongs', () async {
await sync.sync();
expect(
await db.managers.artists
.filter((f) => f.sourceId.equals(sourceId))
.count(),
equals(2),
);
expect(
await db.managers.albums
.filter((f) => f.sourceId.equals(sourceId))
.count(),
equals(3),
);
expect(
await db.managers.songs
.filter((f) => f.sourceId.equals(sourceId))
.count(),
equals(20),
);
expect(
await db.managers.playlists
.filter((f) => f.sourceId.equals(sourceId))
.count(),
equals(1),
);
expect(
await db.managers.playlistSongs
.filter((f) => f.sourceId.equals(sourceId))
.count(),
equals(7),
);
});
}

View File

@@ -64,13 +64,13 @@ void main() {
test('allPlaylists', () async {
final items = await source.allPlaylists().toList();
expect(items.length, equals(0));
expect(items.length, equals(1));
});
test('allPlaylistSongs', () async {
final items = await source.allPlaylistSongs().toList();
expect(items.length, equals(0));
expect(items.length, equals(7));
});
test('album-artist relation', () async {