Add a view to see all books in a collection

This commit is contained in:
2026-04-03 22:57:45 +02:00
parent a5c4c0bbec
commit 625d2a2af1
20 changed files with 285 additions and 44 deletions

View File

@@ -1,10 +1,7 @@
package apitest
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"git.artlef.fr/bibliomane/internal/dto"
@@ -61,20 +58,8 @@ func TestGetBook_IdNotInt(t *testing.T) {
testGetBook(t, "wrong", http.StatusBadRequest)
}
func testGetBook(t *testing.T, id string, status int) dto.FullBookGet {
router := testutils.TestSetup()
token := testutils.ConnectDemoUser(router)
req, _ := http.NewRequest("GET", "/ws/book/"+id, nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
var book dto.FullBookGet
err := json.Unmarshal(w.Body.Bytes(), &book)
if err != nil {
t.Error(err)
}
assert.Equal(t, status, w.Code)
func testGetBook(t *testing.T, id string, expectedStatus int) dto.FullBookGet {
status, book := testutils.TestFetchOneModel[dto.FullBookGet](t, "/ws/book", id)
assert.Equal(t, expectedStatus, status)
return book
}