Create new collections from my collections view

This commit is contained in:
2026-04-03 15:51:18 +02:00
parent b1bad80426
commit b48ab1e4de
11 changed files with 185 additions and 27 deletions

View File

@@ -1,12 +1,8 @@
package apitest
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"
"git.artlef.fr/bibliomane/internal/testutils"
@@ -88,27 +84,7 @@ func TestPostBookHandler_AuthorTooLong(t *testing.T) {
}
func testPostBookHandler(t *testing.T, bookJson string, expectedCode int) uint {
router := testutils.TestSetup()
w := httptest.NewRecorder()
token := testutils.ConnectDemoUser(router)
req, _ := http.NewRequest("POST", "/ws/book",
strings.NewReader(string(bookJson)))
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
router.ServeHTTP(w, req)
assert.Equal(t, expectedCode, w.Code)
if w.Code != http.StatusOK {
return 0
}
var parsed struct {
ID uint
}
err := json.Unmarshal(w.Body.Bytes(), &parsed)
if err != nil {
t.Error(err)
}
return parsed.ID
status, id := testutils.TestPostCall(t, "/ws/book", bookJson)
assert.Equal(t, expectedCode, status)
return id
}