mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-16 19:05:54 -07:00
fix: associate tracks with release when scrobbling (#118)
This commit is contained in:
parent
d327729bff
commit
c346c7cb31
12 changed files with 58 additions and 1794 deletions
|
|
@ -16,55 +16,55 @@ func testDataForTracks(t *testing.T) {
|
|||
|
||||
// Insert artists
|
||||
err := store.Exec(context.Background(),
|
||||
`INSERT INTO artists (musicbrainz_id)
|
||||
`INSERT INTO artists (musicbrainz_id)
|
||||
VALUES ('00000000-0000-0000-0000-000000000001'),
|
||||
('00000000-0000-0000-0000-000000000002')`)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Insert artist aliases
|
||||
err = store.Exec(context.Background(),
|
||||
`INSERT INTO artist_aliases (artist_id, alias, source, is_primary)
|
||||
`INSERT INTO artist_aliases (artist_id, alias, source, is_primary)
|
||||
VALUES (1, 'Artist One', 'Testing', true),
|
||||
(2, 'Artist Two', 'Testing', true)`)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Insert release groups
|
||||
err = store.Exec(context.Background(),
|
||||
`INSERT INTO releases (musicbrainz_id)
|
||||
`INSERT INTO releases (musicbrainz_id)
|
||||
VALUES ('00000000-0000-0000-0000-000000000011'),
|
||||
('00000000-0000-0000-0000-000000000022')`)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Insert release aliases
|
||||
err = store.Exec(context.Background(),
|
||||
`INSERT INTO release_aliases (release_id, alias, source, is_primary)
|
||||
`INSERT INTO release_aliases (release_id, alias, source, is_primary)
|
||||
VALUES (1, 'Release Group One', 'Testing', true),
|
||||
(2, 'Release Group Two', 'Testing', true)`)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Insert tracks
|
||||
err = store.Exec(context.Background(),
|
||||
`INSERT INTO tracks (musicbrainz_id, release_id, duration)
|
||||
`INSERT INTO tracks (musicbrainz_id, release_id, duration)
|
||||
VALUES ('11111111-1111-1111-1111-111111111111', 1, 100),
|
||||
('22222222-2222-2222-2222-222222222222', 2, 100)`)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Insert track aliases
|
||||
err = store.Exec(context.Background(),
|
||||
`INSERT INTO track_aliases (track_id, alias, source, is_primary)
|
||||
`INSERT INTO track_aliases (track_id, alias, source, is_primary)
|
||||
VALUES (1, 'Track One', 'Testing', true),
|
||||
(2, 'Track Two', 'Testing', true)`)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Associate tracks with artists
|
||||
err = store.Exec(context.Background(),
|
||||
`INSERT INTO artist_tracks (artist_id, track_id)
|
||||
`INSERT INTO artist_tracks (artist_id, track_id)
|
||||
VALUES (1, 1), (2, 2)`)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Associate tracks with artists
|
||||
err = store.Exec(context.Background(),
|
||||
`INSERT INTO listens (user_id, track_id, listened_at)
|
||||
`INSERT INTO listens (user_id, track_id, listened_at)
|
||||
VALUES (1, 1, NOW()), (1, 2, NOW())`)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
@ -88,9 +88,10 @@ func TestGetTrack(t *testing.T) {
|
|||
assert.Equal(t, "Track Two", track.Title)
|
||||
assert.EqualValues(t, 100, track.TimeListened)
|
||||
|
||||
// Test GetTrack by Title and ArtistIDs
|
||||
// Test GetTrack by Title, Release and ArtistIDs
|
||||
track, err = store.GetTrack(ctx, db.GetTrackOpts{
|
||||
Title: "Track One",
|
||||
ReleaseID: 1,
|
||||
ArtistIDs: []int32{1},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -99,7 +100,7 @@ func TestGetTrack(t *testing.T) {
|
|||
assert.EqualValues(t, 100, track.TimeListened)
|
||||
|
||||
// Test GetTrack with insufficient information
|
||||
_, err = store.GetTrack(ctx, db.GetTrackOpts{})
|
||||
_, err = store.GetTrack(ctx, db.GetTrackOpts{Title: "Track One"})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
func TestSaveTrack(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue