package api import ( "context" "net/http" "net/http/httptest" "testing" "git.fabledsword.com/bvandeusen/minstrel/internal/lidarrconfig" ) // Helpers shared by the request, quarantine and notification tests. The // Lidarr search they once sat beside is now the catalogue search // (catalogue_test.go, M502 #5519). // resetLidarrState clears requests rows and resets lidarr_config // to the factory-default state (enabled=false, nulls) between tests. func resetLidarrState(t *testing.T, h *handlers) { t.Helper() ctx := context.Background() if _, err := h.pool.Exec(ctx, "DELETE FROM requests; UPDATE lidarr_config SET enabled=false, base_url=NULL, api_key=NULL WHERE id=1", ); err != nil { t.Fatalf("resetLidarrState: %v", err) } } // saveLidarrConfig writes a test lidarr_config row pointing at the given stub URL. func saveLidarrConfig(t *testing.T, h *handlers, baseURL string, enabled bool) { t.Helper() svc := lidarrconfig.New(h.pool) err := svc.Save(context.Background(), lidarrconfig.Config{ Enabled: enabled, BaseURL: baseURL, APIKey: "test-key", DefaultQualityProfileID: 1, DefaultRootFolderPath: "/music", }) if err != nil { t.Fatalf("saveLidarrConfig: %v", err) } } // newLidarrStub creates an httptest.Server that always returns the given body // with 200 OK for any /api/v1/* path. func newLidarrStub(t *testing.T, body string) *httptest.Server { t.Helper() srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) _, _ = w.Write([]byte(body)) })) t.Cleanup(srv.Close) return srv }