Add position for book in collection
This commit is contained in:
@@ -13,14 +13,14 @@ func TestGetCollection_Ok(t *testing.T) {
|
||||
status, collection := testGetCollection(t, "1", "10", "0")
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
assert.Equal(t, "Littérature française", collection.Name)
|
||||
assert.Equal(t, 6, len(collection.Books))
|
||||
assert.Equal(t, 6, len(collection.Items))
|
||||
}
|
||||
|
||||
func TestGetCollection_Limit(t *testing.T) {
|
||||
status, collection := testGetCollection(t, "2", "3", "0")
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
assert.Equal(t, "Nouvelles", collection.Name)
|
||||
assert.Equal(t, 3, len(collection.Books))
|
||||
assert.Equal(t, 3, len(collection.Items))
|
||||
assert.Equal(t, int64(4), collection.Count)
|
||||
}
|
||||
|
||||
@@ -33,10 +33,17 @@ func TestGetCollection_Empty(t *testing.T) {
|
||||
status, collection := testGetCollection(t, "4", "10", "0")
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
assert.Equal(t, "Empty", collection.Name)
|
||||
assert.Equal(t, 0, len(collection.Books))
|
||||
assert.Equal(t, 0, len(collection.Items))
|
||||
assert.Equal(t, int64(0), collection.Count)
|
||||
}
|
||||
|
||||
func TestGetCollection_Position(t *testing.T) {
|
||||
status, collection := testGetCollection(t, "2", "3", "0")
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
assert.Equal(t, "Nouvelles", collection.Name)
|
||||
assert.Equal(t, uint(3), collection.Items[2].Position)
|
||||
}
|
||||
|
||||
func testGetCollection(t *testing.T, id string, limit string, offset string) (int, dto.CollectionGet) {
|
||||
return testutils.TestFetchModel[dto.CollectionGet](t, "/ws/collection/"+id, limit, offset)
|
||||
}
|
||||
|
||||
@@ -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