package playlists_test import ( "context" "testing" "github.com/jackc/pgx/v5/pgtype" "git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq" "git.fabledsword.com/bvandeusen/minstrel/internal/playlists" ) // A mix holds a song once (M498 #5438) and never a held-back video rip // (#5439): of a single and its album cut, the better-ranked copy stays; a rip // is left out and the next copy of its song takes the place. func TestOneCopyPerSong_Integration(t *testing.T) { pool := newPool(t) ctx := context.Background() q := dbq.New(pool) single := seedTrack(t, pool, "copies-single", "copies-artist") albumCut := seedTrack(t, pool, "copies-album-cut", "copies-artist") rip := seedTrack(t, pool, "copies-rip", "copies-artist") clean := seedTrack(t, pool, "copies-clean", "copies-artist") other := seedTrack(t, pool, "copies-other", "copies-artist") for _, pair := range [][]pgtype.UUID{{single.ID, albumCut.ID}, {rip.ID, clean.ID}} { if _, err := q.LinkTracksAsSong(ctx, pair); err != nil { t.Fatal(err) } } if _, err := pool.Exec(ctx, `UPDATE tracks SET source_verdict = 'suspect' WHERE id = $1`, rip.ID); err != nil { t.Fatal(err) } in := []playlists.RankedCandidate{ {TrackID: single.ID}, {TrackID: rip.ID}, {TrackID: albumCut.ID}, {TrackID: other.ID}, {TrackID: clean.ID}, } out, err := playlists.OneCopyPerSong(ctx, q, in) if err != nil { t.Fatal(err) } want := []pgtype.UUID{single.ID, other.ID, clean.ID} if len(out) != len(want) { t.Fatalf("got %d tracks, want %d", len(out), len(want)) } for i, w := range want { if out[i].TrackID != w { t.Errorf("position %d = %s, want %s", i, uuidString(out[i].TrackID), uuidString(w)) } } }