35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
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)
|
|
}
|