release / go (push) Successful in 1m54s
release / web (push) Failing after 5s
release / integration (push) Failing after 3m44s
release / govulncheck (push) Successful in 20s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 19s
release / android (push) Canceled after 2m37s
Minstrel is now a viewer of the library it is pointed at. Finding, downloading and filing music moves out of it. Removed from the server: - the request flow (requests, approval, auto-approve) and the wanted list, follows, release profiles and release blocks; - searching indexers, the download clients, the importer, the album lifecycle and missing-file re-acquisition; - the catalogue's discography, search and art (the MusicBrainz release and track-list cache stays, for the duplicate resolver); - Discover: its suggestions of artists not in the library, snoozes, the candidate-artist tag enrichment and its tuning scope; - writes to acquisition tables from moving the library folder and from merging duplicates, the want-list join on Suspect sources, the sealing of acquisition credentials, and the release-group lookup only re-acquisition used. Settling a wrong-slot duplicate no longer sets the release aside: the copies go and their slots show as missing until a good copy is in the library. Removed from the web: Admin > Acquisition and Requests, /requests, /discover, Follow on the artist page, the auto-approve toggle, and the Collection's wanted-list tabs. The Collection is now the library's health: an overview, Reports, Duplicates, Suspect sources and Missing files. The README and docs no longer describe getting music. The tables stay for now; a later migration drops them. The request notification kinds and the Android screens are still to go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
4.1 KiB
Go
127 lines
4.1 KiB
Go
package api
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"fmt"
|
||
"net/http"
|
||
"net/http/httptest"
|
||
"strings"
|
||
"testing"
|
||
|
||
"github.com/jackc/pgx/v5/pgxpool"
|
||
|
||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||
"git.fabledsword.com/bvandeusen/minstrel/internal/notifications"
|
||
)
|
||
|
||
// inboxItem is one thing the notifier left for one user: kind and decoded
|
||
// payload, newest first.
|
||
type inboxItem struct {
|
||
Kind string
|
||
Payload notifications.Payload
|
||
}
|
||
|
||
func inboxOf(t *testing.T, pool *pgxpool.Pool, user dbq.User) []inboxItem {
|
||
t.Helper()
|
||
rows, err := dbq.New(pool).ListNotifications(context.Background(), dbq.ListNotificationsParams{
|
||
UserID: user.ID, PageLimit: 100,
|
||
})
|
||
if err != nil {
|
||
t.Fatalf("list notifications: %v", err)
|
||
}
|
||
out := make([]inboxItem, 0, len(rows))
|
||
for _, r := range rows {
|
||
var p notifications.Payload
|
||
if err := json.Unmarshal(r.Payload, &p); err != nil {
|
||
t.Fatalf("payload %s: %v", r.Payload, err)
|
||
}
|
||
out = append(out, inboxItem{Kind: r.Kind, Payload: p})
|
||
}
|
||
return out
|
||
}
|
||
|
||
func wantInbox(t *testing.T, who string, got []inboxItem, kinds ...notifications.Kind) {
|
||
t.Helper()
|
||
if len(got) != len(kinds) {
|
||
t.Fatalf("%s inbox = %+v, want kinds %v", who, got, kinds)
|
||
}
|
||
for i, k := range kinds {
|
||
if got[i].Kind != string(k) {
|
||
t.Errorf("%s inbox[%d] = %q, want %q", who, i, got[i].Kind, k)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestNotify_FlagReachesAdminsButNotTheFlagger(t *testing.T) {
|
||
h, pool := testHandlers(t)
|
||
truncateLibrary(t, pool)
|
||
|
||
alice := seedUser(t, pool, "np-flag-alice", "pw", false)
|
||
admin := seedUser(t, pool, "np-flag-admin", "pw", true)
|
||
other := seedUser(t, pool, "np-flag-other", "pw", true)
|
||
track := seedQuarantineTrack(t, h, "np")
|
||
|
||
w := doFlag(h, alice, fmt.Sprintf(`{"track_id":%q,"reason":"bad_rip"}`, uuidToString(track.ID)))
|
||
if w.Code != http.StatusCreated {
|
||
t.Fatalf("flag: status = %d; body = %s", w.Code, w.Body.String())
|
||
}
|
||
got := inboxOf(t, pool, admin)
|
||
wantInbox(t, "admin", got, notifications.KindQuarantineFlagged)
|
||
if p := got[0].Payload; p.Name != "Q Artist np – Q Track np" || p.Actor != alice.Username || p.Reason != "bad rip" {
|
||
t.Errorf("flag payload = %+v", p)
|
||
}
|
||
wantInbox(t, "flagger", inboxOf(t, pool, alice))
|
||
|
||
// An admin flagging a track tells the other admins only.
|
||
track2 := seedQuarantineTrack(t, h, "np2")
|
||
w = doFlag(h, admin, fmt.Sprintf(`{"track_id":%q,"reason":"other"}`, uuidToString(track2.ID)))
|
||
if w.Code != http.StatusCreated {
|
||
t.Fatalf("admin flag: status = %d; body = %s", w.Code, w.Body.String())
|
||
}
|
||
if n := len(inboxOf(t, pool, admin)); n != 1 {
|
||
t.Errorf("flagging admin inbox = %d, want 1 (alice's flag only)", n)
|
||
}
|
||
if n := len(inboxOf(t, pool, other)); n != 2 {
|
||
t.Errorf("other admin inbox = %d, want 2", n)
|
||
}
|
||
}
|
||
|
||
func TestQuarantineReasonLabel(t *testing.T) {
|
||
for in, want := range map[string]string{
|
||
"bad_rip": "bad rip", "wrong_file": "wrong file", "wrong_tags": "wrong tags",
|
||
"duplicate": "duplicate", "other": "", "": "",
|
||
} {
|
||
if got := quarantineReasonLabel(in); got != want {
|
||
t.Errorf("quarantineReasonLabel(%q) = %q, want %q", in, got, want)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestNotify_PlaybackErrorsCoalesceIntoOneCount(t *testing.T) {
|
||
h, pool := testHandlers(t)
|
||
truncateLibrary(t, pool)
|
||
|
||
alice := seedUser(t, pool, "np-play-alice", "pw", false)
|
||
admin := seedUser(t, pool, "np-play-admin", "pw", true)
|
||
track := seedQuarantineTrack(t, h, "play")
|
||
|
||
for i := 0; i < 2; i++ {
|
||
body := fmt.Sprintf(`{"track_id":%q,"kind":"load_failed","client_id":"web-%d"}`, uuidToString(track.ID), i)
|
||
req := withUser(httptest.NewRequest(http.MethodPost, "/api/playback-errors", strings.NewReader(body)), alice)
|
||
w := httptest.NewRecorder()
|
||
h.handleReportPlaybackError(w, req)
|
||
if w.Code != http.StatusCreated {
|
||
t.Fatalf("report %d: status = %d; body = %s", i, w.Code, w.Body.String())
|
||
}
|
||
}
|
||
|
||
got := inboxOf(t, pool, admin)
|
||
wantInbox(t, "admin", got, notifications.KindPlaybackErrors)
|
||
if got[0].Payload.Count != 2 || len(got[0].Payload.Items) != 2 ||
|
||
!strings.HasSuffix(got[0].Payload.Items[0], "np-play-alice)") {
|
||
t.Errorf("payload = %+v, want two reports, each naming the track and alice", got[0].Payload)
|
||
}
|
||
wantInbox(t, "reporter", inboxOf(t, pool, alice))
|
||
}
|