First implementation of fetching collections of book managed by user

This commit is contained in:
2026-04-02 16:23:22 +02:00
parent acdc3972bd
commit a280647575
18 changed files with 377 additions and 41 deletions

View File

@@ -6,6 +6,8 @@ import (
"log"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
@@ -65,3 +67,40 @@ func TestBookPutCallWithDemoPayload(t *testing.T, payload string, bookId string,
t.Errorf("%s", w.Body.String())
}
}
func TestFetchModel[T any](t *testing.T, urlpath string, limit string, offset string) (int, T) {
router := TestSetup()
u, err := url.Parse(urlpath)
if err != nil {
t.Error(err)
}
if limit != "" {
q := u.Query()
q.Set("limit", limit)
u.RawQuery = q.Encode()
}
if offset != "" {
q := u.Query()
q.Set("offset", offset)
u.RawQuery = q.Encode()
}
q := u.Query()
q.Set("lang", "fr")
u.RawQuery = q.Encode()
token := ConnectDemoUser(router)
req, _ := http.NewRequest("GET", u.String(), nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var result T
s := w.Body.String()
err = json.Unmarshal([]byte(s), &result)
if err != nil {
t.Error(err)
}
return w.Code, result
}