package pocketbase import ( "context" "encoding/json" "net/http" "net/http/httptest" "testing" ) func TestGetBookmarkURLs_Success(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // No auth needed - just return records. if r.URL.Path != "/" { t.Errorf("Expected path '/', got '%s'", r.URL.Path) } // Verify query params. if r.URL.Query().Get("perPage") != "200" { t.Errorf("Expected perPage=200, got '%s'", r.URL.Query().Get("perPage")) } if r.URL.Query().Get("fields") != "url" { t.Errorf("Expected fields=url, got '%s'", r.URL.Query().Get("fields")) } w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(recordsResponse{ Items: []record{ {URL: "https://royalroad.com/fiction/1"}, {URL: "https://royalroad.com/fiction/2"}, }, }) })) defer server.Close() client := New(server.URL) urls, err := client.GetBookmarkURLs(context.Background()) if err != nil { t.Fatalf("Unexpected error: %v", err) } if len(urls) != 2 { t.Errorf("Expected 2 URLs, got %d", len(urls)) } if urls[0] != "https://royalroad.com/fiction/1" { t.Errorf("Unexpected first URL: %s", urls[0]) } } func TestGetBookmarkURLs_Non200(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) })) defer server.Close() client := New(server.URL) _, err := client.GetBookmarkURLs(context.Background()) if err == nil { t.Error("Expected error on non-200 status, got nil") } }