release / web (push) Successful in 1m34s
release / go (push) Successful in 2m0s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m24s
release / android (push) Successful in 4m46s
release / Build signed APK (push) Successful in 5m12s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- The like/unlike story runs as one sequence that checks the rows after each step. - The invite-only sign-up cases are one test, which now also checks that a refused sign-up creates no account. - Demoting an admin, and stopping at the last one, is one test. - A wrong password and an unknown user are one test, which now also checks that the two refusals are identical. - The cover-path resolver tests repeated the cover handler's tests branch for branch; the handler tests stay. - The Range-from-start stream test only re-checked http.ServeContent. - The APK's nil-user 401 is covered by the mounted-route walk. - 68 copies of the MINSTREL_TEST_DATABASE_URL skip go: every one of those tests reaches dbtest.Pool, which already skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
2.8 KiB
Go
88 lines
2.8 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
// Generic registry-driven system-playlist endpoints.
|
|
func newSystemPlaylistRouter(h *handlers) chi.Router {
|
|
r := chi.NewRouter()
|
|
r.Route("/api", func(api chi.Router) {
|
|
// No real auth.RequireUser middleware: like every other api
|
|
// handler test, auth is supplied via withUser() context and the
|
|
// handlers self-guard with requireUser() (prelude.go). The real
|
|
// middleware needs a live session and would 401 the injected
|
|
// test user.
|
|
api.Post("/playlists/system/{kind}/refresh", h.handleSystemPlaylistRefresh)
|
|
api.Get("/playlists/system/{kind}/shuffle", h.handleSystemPlaylistShuffle)
|
|
})
|
|
return r
|
|
}
|
|
|
|
func TestSystemRefresh_ForYou_Returns200(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
user := seedUser(t, pool, "sysforyou", "pw", false)
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/api/playlists/system/for_you/refresh", nil)
|
|
req = withUser(req, user)
|
|
rec := httptest.NewRecorder()
|
|
newSystemPlaylistRouter(h).ServeHTTP(rec, req)
|
|
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("status = %d, want 200; body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
var resp systemRefreshResp
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if resp.TrackIDs == nil {
|
|
t.Errorf("track_ids = nil, want [] (empty array, not null)")
|
|
}
|
|
if int(resp.TrackCount) != len(resp.TrackIDs) {
|
|
t.Errorf("track_count=%d, len(track_ids)=%d — mismatch", resp.TrackCount, len(resp.TrackIDs))
|
|
}
|
|
}
|
|
|
|
func TestSystemRefresh_Discover_Returns200(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
user := seedUser(t, pool, "sysdiscover", "pw", false)
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/api/playlists/system/discover/refresh", nil)
|
|
req = withUser(req, user)
|
|
rec := httptest.NewRecorder()
|
|
newSystemPlaylistRouter(h).ServeHTTP(rec, req)
|
|
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("status = %d, want 200; body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
var resp systemRefreshResp
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if resp.TrackCount < 0 {
|
|
t.Errorf("track_count = %d, want >= 0", resp.TrackCount)
|
|
}
|
|
}
|
|
|
|
// A non-singleton (songs_like_artist) or unknown kind isn't
|
|
// addressable by the generic endpoints → 404, not a build.
|
|
func TestSystemRefresh_NonSingletonKind_Returns404(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
user := seedUser(t, pool, "sysbadkind", "pw", false)
|
|
|
|
for _, kind := range []string{"songs_like_artist", "bogus"} {
|
|
req := httptest.NewRequest(http.MethodPost, "/api/playlists/system/"+kind+"/refresh", nil)
|
|
req = withUser(req, user)
|
|
rec := httptest.NewRecorder()
|
|
newSystemPlaylistRouter(h).ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusNotFound {
|
|
t.Errorf("kind=%s: status = %d, want 404", kind, rec.Code)
|
|
}
|
|
}
|
|
}
|