Collections browser: add a button to remove collections
This commit is contained in:
51
internal/apitest/delete_collection_test.go
Normal file
51
internal/apitest/delete_collection_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package apitest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.artlef.fr/bibliomane/internal/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDeleteCollectionHandler_EmptyCollection(t *testing.T) {
|
||||
collectionId := "8"
|
||||
status := testDeleteCollectionHandler(collectionId)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
getStatus, _ := testGetCollection(t, collectionId, "10", "0")
|
||||
assert.Equal(t, http.StatusNotFound, getStatus)
|
||||
}
|
||||
|
||||
func TestDeleteCollectionHandler_NotEmptyCollection(t *testing.T) {
|
||||
collectionId := "7"
|
||||
status := testDeleteCollectionHandler(collectionId)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
getStatus, _ := testGetCollection(t, collectionId, "10", "0")
|
||||
assert.Equal(t, http.StatusNotFound, getStatus)
|
||||
}
|
||||
|
||||
func TestDeleteCollectionHandler_NonExistingCollection(t *testing.T) {
|
||||
collectionId := "425"
|
||||
status := testDeleteCollectionHandler(collectionId)
|
||||
assert.Equal(t, http.StatusNotFound, status)
|
||||
}
|
||||
|
||||
func TestDeleteCollectionHandler_ForbiddenCollection(t *testing.T) {
|
||||
collectionId := "3"
|
||||
status := testDeleteCollectionHandler(collectionId)
|
||||
assert.Equal(t, http.StatusUnauthorized, status)
|
||||
}
|
||||
|
||||
func testDeleteCollectionHandler(id string) int {
|
||||
router := testutils.TestSetup()
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
token := testutils.ConnectDemoUser(router)
|
||||
req, _ := http.NewRequest("DELETE", "/ws/collection/"+id, nil)
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
return w.Code
|
||||
}
|
||||
Reference in New Issue
Block a user