Collection form: add a button to remove added books
This commit is contained in:
45
internal/apitest/delete_collection_element_test.go
Normal file
45
internal/apitest/delete_collection_element_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package apitest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.artlef.fr/bibliomane/internal/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDeleteCollectionBookHandler_DelOk(t *testing.T) {
|
||||
status := testDeleteCollectionBookHandler("23")
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
_, collection := testGetCollection(t, "6", "10", "0")
|
||||
assert.Equal(t, int64(5), collection.Count)
|
||||
assert.Equal(t, uint(1), collection.Items[0].Position)
|
||||
assert.Equal(t, uint(2), collection.Items[1].Position)
|
||||
assert.Equal(t, uint(3), collection.Items[2].Position)
|
||||
assert.Equal(t, uint(4), collection.Items[3].Position)
|
||||
assert.Equal(t, uint(5), collection.Items[4].Position)
|
||||
}
|
||||
|
||||
func TestDeleteCollectionBookHandler_NotFound(t *testing.T) {
|
||||
status := testDeleteCollectionBookHandler("425")
|
||||
assert.Equal(t, http.StatusNotFound, status)
|
||||
}
|
||||
|
||||
func TestDeleteCollectionBookHandler_Unauthorized(t *testing.T) {
|
||||
status := testDeleteCollectionBookHandler("11")
|
||||
assert.Equal(t, http.StatusUnauthorized, status)
|
||||
}
|
||||
|
||||
func testDeleteCollectionBookHandler(itemId string) int {
|
||||
router := testutils.TestSetup()
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
token := testutils.ConnectDemoUser(router)
|
||||
req, _ := http.NewRequest("DELETE", "/ws/collection/item/"+itemId, nil)
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
return w.Code
|
||||
}
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
func TestFetchAllCollections_OK(t *testing.T) {
|
||||
status, res := testFetchCollections(t, "10", "0")
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
assert.Equal(t, int64(4), res.Count)
|
||||
assert.Equal(t, 4, len(res.Collections))
|
||||
assert.Equal(t, int64(5), res.Count)
|
||||
assert.Equal(t, 5, len(res.Collections))
|
||||
}
|
||||
|
||||
func testFetchCollections(t *testing.T, limit string, offset string) (int, dto.CollectionItemsGet) {
|
||||
|
||||
Reference in New Issue
Block a user