Create new collections from my collections view
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user