Add a view to see all books in a collection
This commit is contained in:
34
internal/apitest/get_collection_test.go
Normal file
34
internal/apitest/get_collection_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package apitest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"git.artlef.fr/bibliomane/internal/dto"
|
||||
"git.artlef.fr/bibliomane/internal/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
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, int64(4), collection.Count)
|
||||
}
|
||||
|
||||
func TestGetCollection_Unauthorized(t *testing.T) {
|
||||
status, _ := testGetCollection(t, "4", "10", "0")
|
||||
assert.Equal(t, http.StatusUnauthorized, status)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user