Add an user management page for admins
This commit is contained in:
41
internal/apitest/get_users_test.go
Normal file
41
internal/apitest/get_users_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package apitest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"git.artlef.fr/bibliomane/internal/dto"
|
||||
"git.artlef.fr/bibliomane/internal/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetUsersHandler_OK(t *testing.T) {
|
||||
status, result := testFetchUsers(t, "15", "0")
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
assert.Equal(t, int64(3), result.Count)
|
||||
assert.Equal(t, 3, len(result.Users))
|
||||
}
|
||||
|
||||
func TestGetUsersHandler_Limit(t *testing.T) {
|
||||
status, result := testFetchUsers(t, "2", "0")
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
assert.Equal(t, int64(3), result.Count)
|
||||
assert.Equal(t, 2, len(result.Users))
|
||||
}
|
||||
|
||||
func TestGetUsersHandler_Forbidden(t *testing.T) {
|
||||
status, _ := testutils.TestFetchModel[dto.UsersGet](t, "/ws/admin/users", "10", "0")
|
||||
assert.Equal(t, http.StatusForbidden, status)
|
||||
}
|
||||
|
||||
func TestGetUsersHandler_BookCountOK(t *testing.T) {
|
||||
status, result := testFetchUsers(t, "1", "1")
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
assert.Equal(t, "demo2", result.Users[0].Name)
|
||||
assert.Equal(t, int64(1), result.Users[0].AddedBooksCount)
|
||||
assert.Equal(t, int64(3), result.Users[0].UserBooksCount)
|
||||
}
|
||||
|
||||
func testFetchUsers(t *testing.T, limit string, offset string) (int, dto.UsersGet) {
|
||||
return testutils.TestFetchAdminModel[dto.UsersGet](t, "/ws/admin/users", limit, offset)
|
||||
}
|
||||
Reference in New Issue
Block a user