PocketBase view collection benutzen. Dokumentation aktualisieren.

This commit is contained in:
2026-07-14 20:06:19 +02:00
parent a1504dd5e6
commit b8b4e00b92
10 changed files with 162 additions and 138 deletions

View File

@@ -10,29 +10,28 @@ import (
func TestGetBookmarkURLs_Success(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/api/collections/users/auth-with-password" {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(authResponse{Token: "test-token"})
return
// No auth needed - just return records.
if r.URL.Path != "/" {
t.Errorf("Expected path '/', got '%s'", r.URL.Path)
}
if r.URL.Path == "/api/collections/bookmarks/records" {
if r.Header.Get("Authorization") != "test-token" {
t.Errorf("Expected Authorization header 'test-token', got '%s'", r.Header.Get("Authorization"))
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(recordsResponse{
Items: []record{
{URL: "https://royalroad.com/fiction/1"},
{URL: "https://royalroad.com/fiction/2"},
},
})
return
// Verify query params.
if r.URL.Query().Get("perPage") != "200" {
t.Errorf("Expected perPage=200, got '%s'", r.URL.Query().Get("perPage"))
}
t.Errorf("Unexpected request to %s", r.URL.Path)
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, "user", "pass", "Geschichten")
client := New(server.URL)
urls, err := client.GetBookmarkURLs(context.Background())
if err != nil {
@@ -46,20 +45,16 @@ func TestGetBookmarkURLs_Success(t *testing.T) {
}
}
func TestGetBookmarkURLs_AuthFailure(t *testing.T) {
func TestGetBookmarkURLs_Non200(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/api/collections/users/auth-with-password" {
w.WriteHeader(http.StatusUnauthorized)
return
}
t.Errorf("Unexpected request to %s", r.URL.Path)
w.WriteHeader(http.StatusInternalServerError)
}))
defer server.Close()
client := New(server.URL, "user", "pass", "Geschichten")
client := New(server.URL)
_, err := client.GetBookmarkURLs(context.Background())
if err == nil {
t.Error("Expected error on auth failure, got nil")
t.Error("Expected error on non-200 status, got nil")
}
}