Files
minstrel/internal/subsonic/getalbum_test.go
T
bvandeusenandClaude Opus 5.5 f4336cdc23
release / go (push) Successful in 1m52s
release / web (push) Successful in 1m6s
release / integration (push) Successful in 4m15s
release / govulncheck (push) Successful in 23s
release / android (push) Successful in 4m9s
release / Build signed APK (push) Successful in 4m39s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 23s
release / Verify release artifacts (tag releases only) (push) Skipped
fix: an album's tracks are credited to their own artists, not all to the album's
Albums are now filed under their album artist, so a compilation's tracks
and a featured guest's track have a different artist from their album.
The web album page and Subsonic getAlbum named every track after the
album's artist, so a compilation read Various Artists on every row. Both
now name each track by its own artist, read in one query, and fall back
to the album's artist if that lookup fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 10:05:58 -05:00

87 lines
2.7 KiB
Go

package subsonic
import (
"context"
"encoding/json"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/jackc/pgx/v5/pgxpool"
"git.fabledsword.com/bvandeusen/minstrel/internal/db"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
)
// A compilation's songs are credited to their own performers, as Subsonic
// clients show them, not all to Various Artists.
func TestGetAlbum_EachSongCreditsItsOwnArtist(t *testing.T) {
if testing.Short() {
t.Skip("skipping in -short mode")
}
dsn := os.Getenv("MINSTREL_TEST_DATABASE_URL")
if dsn == "" {
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
}
if err := db.Migrate(dsn, slog.New(slog.NewTextHandler(io.Discard, nil))); err != nil {
t.Fatalf("migrate: %v", err)
}
pool, err := pgxpool.New(context.Background(), dsn)
if err != nil {
t.Fatalf("pool: %v", err)
}
t.Cleanup(pool.Close)
dbtest.ResetDB(t, pool)
ctx := context.Background()
q := dbq.New(pool)
artist := func(name string) dbq.Artist {
a, err := q.UpsertArtist(ctx, dbq.UpsertArtistParams{Name: name, SortName: name})
if err != nil {
t.Fatalf("artist %s: %v", name, err)
}
return a
}
various, first, guest := artist("Various Artists"), artist("Harbour Choir"), artist("Ruby Lane")
album, err := q.UpsertAlbum(ctx, dbq.UpsertAlbumParams{Title: "Sunday Morning Static", SortTitle: "Sunday Morning Static", ArtistID: various.ID})
if err != nil {
t.Fatalf("album: %v", err)
}
n1, n2 := int32(1), int32(2)
for _, tr := range []dbq.UpsertTrackParams{
{Title: "Low Light", AlbumID: album.ID, ArtistID: first.ID, TrackNumber: &n1, FilePath: "/tmp/getalbum-1.flac", DurationMs: 100_000},
{Title: "Saltlines", AlbumID: album.ID, ArtistID: guest.ID, TrackNumber: &n2, FilePath: "/tmp/getalbum-2.flac", DurationMs: 100_000},
} {
if _, err := q.UpsertTrack(ctx, tr); err != nil {
t.Fatalf("track %s: %v", tr.Title, err)
}
}
b := &browseHandlers{pool: pool}
req := httptest.NewRequest(http.MethodGet, "/rest/getAlbum?f=json&id="+uuidToID(album.ID), nil)
w := httptest.NewRecorder()
b.getAlbum(w, req)
if w.Code != http.StatusOK {
t.Fatalf("status = %d body=%s", w.Code, w.Body.String())
}
var raw struct {
Response struct {
Album AlbumDetail `json:"album"`
} `json:"subsonic-response"`
}
if err := json.Unmarshal(w.Body.Bytes(), &raw); err != nil {
t.Fatalf("decode: %v body=%s", err, w.Body.String())
}
got := raw.Response.Album
if got.Artist != "Various Artists" {
t.Errorf("album artist = %q, want Various Artists", got.Artist)
}
if len(got.Songs) != 2 || got.Songs[0].Artist != "Harbour Choir" || got.Songs[1].Artist != "Ruby Lane" {
t.Errorf("songs = %+v, want each song credited to its own artist", got.Songs)
}
}