release / web (push) Successful in 1m59s
release / go (push) Successful in 2m23s
release / govulncheck (push) Successful in 22s
release / integration (push) Successful in 4m59s
release / android (push) Successful in 5m29s
release / Build signed APK (push) Successful in 6m26s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 31s
release / Verify release artifacts (tag releases only) (push) Skipped
Minstrel fetched artist pictures but showed them only to Subsonic apps.
GET /api/artists/{id}/image now serves the picture, or else the artist's
newest album cover, the same image Subsonic apps get. Artist listings
point at it when the artist has a picture and keep the album cover
otherwise; the artist page points at it whenever the artist has albums,
and the web artist page shows it beside the name.
Android shows the picture for cached artists that have one, and the
album cover for the rest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
3.7 KiB
Go
108 lines
3.7 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// getArt fetches path and returns the image body, or "" with the status
|
|
// when the answer is not an image.
|
|
func getArt(t *testing.T, h *handlers, path string) (string, int) {
|
|
t.Helper()
|
|
w := httptest.NewRecorder()
|
|
newLibraryRouter(h).ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil))
|
|
if w.Code != http.StatusOK {
|
|
return "", w.Code
|
|
}
|
|
return w.Body.String(), w.Code
|
|
}
|
|
|
|
// coverURLs returns the cover_url of every artist in the alphabetical
|
|
// listing, by name.
|
|
func coverURLs(t *testing.T, h *handlers) map[string]string {
|
|
t.Helper()
|
|
w := httptest.NewRecorder()
|
|
newLibraryRouter(h).ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/artists", nil))
|
|
var got Page[ArtistRef]
|
|
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
|
t.Fatalf("decode artists: %v body=%s", err, w.Body.String())
|
|
}
|
|
out := map[string]string{}
|
|
for _, a := range got.Items {
|
|
out[a.Name] = a.CoverURL
|
|
}
|
|
return out
|
|
}
|
|
|
|
func detailCoverURL(t *testing.T, h *handlers, id string) string {
|
|
t.Helper()
|
|
w := httptest.NewRecorder()
|
|
newLibraryRouter(h).ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/api/artists/"+id, nil))
|
|
var got ArtistDetail
|
|
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
|
t.Fatalf("decode artist: %v body=%s", err, w.Body.String())
|
|
}
|
|
return got.CoverURL
|
|
}
|
|
|
|
func exec(t *testing.T, pool *pgxpool.Pool, sql string, args ...any) {
|
|
t.Helper()
|
|
if _, err := pool.Exec(context.Background(), sql, args...); err != nil {
|
|
t.Fatalf("%s: %v", sql, err)
|
|
}
|
|
}
|
|
|
|
// An artist's image is the picture fetched for them, or else their newest
|
|
// album cover; artist listings point at it when there is a picture, and the
|
|
// artist page whenever the artist has albums.
|
|
func TestArtistImage_PictureOrNewestAlbumCover(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
truncateLibrary(t, pool)
|
|
dir := t.TempDir()
|
|
write := func(name, body string) string {
|
|
path := filepath.Join(dir, name)
|
|
if err := os.WriteFile(path, []byte(body), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return path
|
|
}
|
|
orchard := seedArtist(t, pool, "Tin Orchard")
|
|
album := seedAlbum(t, pool, orchard.ID, "Paper Boats", 2012)
|
|
exec(t, pool, `UPDATE albums SET cover_art_path = $2 WHERE id = $1`, album.ID, write("boats.jpg", "boats"))
|
|
quiet := seedArtist(t, pool, "Quiet Field")
|
|
orchardImage := "/api/artists/" + uuidToString(orchard.ID) + "/image"
|
|
albumCover := "/api/albums/" + uuidToString(album.ID) + "/cover"
|
|
|
|
if got, code := getArt(t, h, orchardImage); got != "boats" {
|
|
t.Errorf("no picture: got %q (status %d), want the album cover", got, code)
|
|
}
|
|
if got := coverURLs(t, h); got["Tin Orchard"] != albumCover || got["Quiet Field"] != "" {
|
|
t.Errorf("no picture: listing cover_url = %v, want the album cover for Tin Orchard and none for Quiet Field", got)
|
|
}
|
|
|
|
exec(t, pool, `UPDATE artists SET artist_thumb_path = $2 WHERE id = $1`, orchard.ID, write("thumb.jpg", "thumb"))
|
|
if got, code := getArt(t, h, orchardImage); got != "thumb" {
|
|
t.Errorf("with a picture: got %q (status %d), want the picture", got, code)
|
|
}
|
|
if got := coverURLs(t, h); got["Tin Orchard"] != orchardImage {
|
|
t.Errorf("with a picture: listing cover_url = %q, want %q", got["Tin Orchard"], orchardImage)
|
|
}
|
|
|
|
if got := detailCoverURL(t, h, uuidToString(orchard.ID)); got != orchardImage {
|
|
t.Errorf("artist page cover_url = %q, want %q", got, orchardImage)
|
|
}
|
|
if got := detailCoverURL(t, h, uuidToString(quiet.ID)); got != "" {
|
|
t.Errorf("artist page with no albums: cover_url = %q, want none", got)
|
|
}
|
|
if _, code := getArt(t, h, "/api/artists/"+uuidToString(quiet.ID)+"/image"); code != http.StatusNotFound {
|
|
t.Errorf("no picture and no albums: status %d, want 404", code)
|
|
}
|
|
}
|