Add position for book in collection
This commit is contained in:
@@ -11,24 +11,36 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPostCollectionBookHandler_Ok(t *testing.T) {
|
||||
func TestPostCollectionBookHandler_AddOk(t *testing.T) {
|
||||
payload :=
|
||||
`{
|
||||
"bookId": 9
|
||||
}`
|
||||
collectionId := "1"
|
||||
status := testPostCollectionBookHandler(t, collectionId, payload)
|
||||
status := testPostCollectionBookHandler(collectionId, payload)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
_, collection := testGetCollection(t, collectionId, "10", "0")
|
||||
assert.Equal(t, int64(7), collection.Count)
|
||||
}
|
||||
|
||||
func TestPostCollectionBookHandler_BookOK(t *testing.T) {
|
||||
payload :=
|
||||
`{
|
||||
"bookId": 7
|
||||
}`
|
||||
collectionId := "2"
|
||||
status := testPostCollectionBookHandler(collectionId, payload)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
_, collection := testGetCollection(t, collectionId, "10", "0")
|
||||
assert.Equal(t, uint(7), collection.Items[0].Book.ID)
|
||||
}
|
||||
|
||||
func TestPostCollectionBookHandler_CollectionNotFound(t *testing.T) {
|
||||
payload :=
|
||||
`{
|
||||
"bookId": 9
|
||||
}`
|
||||
status := testPostCollectionBookHandler(t, "12", payload)
|
||||
status := testPostCollectionBookHandler("12", payload)
|
||||
assert.Equal(t, http.StatusNotFound, status)
|
||||
}
|
||||
|
||||
@@ -37,7 +49,7 @@ func TestPostCollectionBookHandler_BookNotFound(t *testing.T) {
|
||||
`{
|
||||
"bookId": 14654
|
||||
}`
|
||||
status := testPostCollectionBookHandler(t, "1", payload)
|
||||
status := testPostCollectionBookHandler("1", payload)
|
||||
assert.Equal(t, http.StatusNotFound, status)
|
||||
}
|
||||
|
||||
@@ -46,11 +58,11 @@ func TestPostCollectionBookHandler_Unauthorized(t *testing.T) {
|
||||
`{
|
||||
"bookId": 9
|
||||
}`
|
||||
status := testPostCollectionBookHandler(t, "3", payload)
|
||||
status := testPostCollectionBookHandler("3", payload)
|
||||
assert.Equal(t, http.StatusUnauthorized, status)
|
||||
}
|
||||
|
||||
func testPostCollectionBookHandler(t *testing.T, collectionId string, payload string) int {
|
||||
func testPostCollectionBookHandler(collectionId string, payload string) int {
|
||||
router := testutils.TestSetup()
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user