Add a view to see all books in a collection
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user