improve album tests

This commit is contained in:
austinried
2025-11-02 18:35:13 +09:00
parent c900c9750a
commit 2df86f4faa
9 changed files with 399 additions and 37 deletions

View File

@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:http/http.dart';
import 'package:subtracks/sources/subsonic/client.dart';
import 'package:subtracks/sources/subsonic/source.dart';
@@ -56,6 +57,33 @@ void main() {
final items = await source.allAlbums().toList();
expect(items.length, equals(3));
final kosmo = items.firstWhere((a) => a.name == 'Kosmonaut');
expect(kosmo.id.length, greaterThan(0));
expect(kosmo.artistId?.length, greaterThan(0));
expect(kosmo.albumArtist, equals('Ugress'));
expect(kosmo.created.compareTo(DateTime.now()), lessThan(0));
expect(kosmo.coverArt?.length, greaterThan(0));
expect(kosmo.year, equals(2006));
expect(kosmo.starred, isNull);
expect(kosmo.genre, equals('Electronic'));
final retro = items.firstWhere(
(a) => a.name == 'Retroconnaissance EP',
);
final dunno = items.firstWhere(
(a) => a.name == "I Don't Know What I'm Doing",
);
expect(kosmo.recentRank, equals(0));
expect(kosmo.frequentRank, equals(1));
expect(retro.recentRank, equals(1));
expect(retro.frequentRank, equals(0));
expect(dunno.recentRank, isNull);
expect(dunno.frequentRank, isNull);
});
test('allArtists', () async {
@@ -81,6 +109,39 @@ void main() {
expect(items.length, equals(0));
});
test('album-artist relation', () async {
final artists = await source.allArtists().toList();
final albums = await source.allAlbums().toList();
final artistAlbums = artists
.map(
(artist) => [
artist.name,
...albums
.where((album) => album.artistId == artist.id)
.map((album) => album.name)
.sorted(),
],
)
.sorted((a, b) => (a[0]).compareTo(b[0]));
expect(artistAlbums.length, equals(2));
expect(
artistAlbums,
equals([
[
'Brad Sucks',
"I Don't Know What I'm Doing",
],
[
'Ugress',
'Kosmonaut',
'Retroconnaissance EP',
],
]),
);
});
});
}
}