Skip to content

Commit 40c2a28

Browse files
committed
Assert more props returned by in the GetArtistAlbums
1 parent 8f07bf2 commit 40c2a28

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

src/library/library_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ func TestLocalLibraryGetArtistAlbums(t *testing.T) {
12541254
albumName = "Return Of The Bugs"
12551255
secondAlbumName = "Return Of The Bugs II Deluxe 3000"
12561256
artistName = "Buggy Bugoff"
1257+
albumYear = 2014
12571258
)
12581259

12591260
tracks := []struct {
@@ -1267,6 +1268,7 @@ func TestLocalLibraryGetArtistAlbums(t *testing.T) {
12671268
title: "Payback",
12681269
track: 1,
12691270
length: 340 * time.Second,
1271+
year: albumYear,
12701272
},
12711273
path: "/media/return-of-the-bugs/track-1.mp3",
12721274
},
@@ -1277,6 +1279,7 @@ func TestLocalLibraryGetArtistAlbums(t *testing.T) {
12771279
title: "Realization",
12781280
track: 2,
12791281
length: 345 * time.Second,
1282+
year: albumYear,
12801283
},
12811284
path: "/media/return-of-the-bugs/track-2.mp3",
12821285
},
@@ -1306,6 +1309,7 @@ func TestLocalLibraryGetArtistAlbums(t *testing.T) {
13061309
albumName: {
13071310
Name: albumName,
13081311
Artist: artistName,
1312+
Year: albumYear,
13091313
},
13101314
secondAlbumName: {
13111315
Name: secondAlbumName,
@@ -1336,6 +1340,39 @@ func TestLocalLibraryGetArtistAlbums(t *testing.T) {
13361340
expected[al.Name] = al
13371341
}
13381342

1343+
// Record some plays, set favourite and rating for an album.
1344+
toRecordTracks := lib.Search(ctx, SearchArgs{Query: "Index By Index"})
1345+
if len(toRecordTracks) != 1 {
1346+
t.Fatalf("could not find album to record plays to")
1347+
}
1348+
1349+
recordTime := time.Now()
1350+
favs := Favourites{
1351+
AlbumIDs: []int64{toRecordTracks[0].AlbumID},
1352+
}
1353+
if err := lib.RecordFavourite(ctx, favs); err != nil {
1354+
t.Fatalf("failed to set album '%s' as favourite: %s",
1355+
toRecordTracks[0].Album, err,
1356+
)
1357+
}
1358+
if err := lib.RecordTrackPlay(ctx, toRecordTracks[0].ID, recordTime); err != nil {
1359+
t.Fatalf("failed to record play for track: %s", err)
1360+
}
1361+
if err := lib.SetAlbumRating(ctx, toRecordTracks[0].AlbumID, 3); err != nil {
1362+
t.Fatalf("failed to set album rating: %s", err)
1363+
}
1364+
1365+
secAlbum, ok := expected[secondAlbumName]
1366+
if !ok {
1367+
t.Fatalf("wrong test, `%s` is missing from expected", secondAlbumName)
1368+
}
1369+
1370+
secAlbum.Favourite = recordTime.Unix()
1371+
secAlbum.LastPlayed = recordTime.Unix()
1372+
secAlbum.Plays = 1
1373+
secAlbum.Rating = 3
1374+
expected[secondAlbumName] = secAlbum
1375+
13391376
var artistID int64
13401377
results := lib.Search(ctx, SearchArgs{Query: artistName})
13411378
for _, track := range results {
@@ -1377,6 +1414,21 @@ func TestLocalLibraryGetArtistAlbums(t *testing.T) {
13771414
album.Duration,
13781415
)
13791416
}
1417+
assert.Equal(t, expectedAlbum.LastPlayed, album.LastPlayed,
1418+
"album `%s` last played timestamp", album.Name,
1419+
)
1420+
assert.Equal(t, expectedAlbum.Plays, album.Plays,
1421+
"album `%s` plays count", album.Name,
1422+
)
1423+
assert.Equal(t, expectedAlbum.Favourite, album.Favourite,
1424+
"album `%s` favourite timestamp", album.Name,
1425+
)
1426+
assert.Equal(t, expectedAlbum.Rating, album.Rating,
1427+
"album `%s` rating", album.Name,
1428+
)
1429+
assert.Equal(t, expectedAlbum.Year, album.Year,
1430+
"album `%s` year", album.Name,
1431+
)
13801432
}
13811433

13821434
if !found {

src/library/local_browse_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ func TestBrowsingTracks(t *testing.T) {
958958
expected: []string{
959959
"No Way",
960960
},
961-
total: allTracksCount,
961+
total: 7, // one track does not have an year
962962
},
963963
}
964964

src/library/mock_media_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ func (m *MockMedia) Length() time.Duration {
4141
// Year satisfies the MediaFile interface. Returns the object attribute or a default
4242
// value if one is not set.
4343
func (m *MockMedia) Year() int {
44-
if m.year == 0 {
45-
return 1984
46-
}
4744
return m.year
4845
}
4946

0 commit comments

Comments
 (0)