mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00

Every test will fail except from the user's package since it is the only one using the new Request type.
41 lines
985 B
Go
41 lines
985 B
Go
package user
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
|
)
|
|
|
|
func TestUserEndpoints(t *testing.T) {
|
|
|
|
db := common.DummyInitDB()
|
|
defer db.Close()
|
|
common.DummyOnlyAdminDB(db)
|
|
|
|
router := gin.Default()
|
|
api := router.Group("/api")
|
|
|
|
VisitorAuthenticate(api.Group("/authenticate"))
|
|
api.Use(Authentication(true))
|
|
RegisterUserEndpoints(api.Group("/users"))
|
|
|
|
// authenticate
|
|
token, err := common.NewAuthenticateForTest(router,
|
|
"/api/authenticate", "POST", common.AdminCredentials, 200)
|
|
assert.NoError(t, err)
|
|
|
|
// test GET user/
|
|
err = common.NewTestEndpoint(router, token,
|
|
"/api/users", "GET", nil,
|
|
200, common.KeyModels{"users": []common.User{common.User0}})
|
|
assert.NoError(t, err)
|
|
|
|
// test GET user/1 (the admin)
|
|
err = common.NewTestEndpoint(router, token,
|
|
"/api/users/1", "GET", nil,
|
|
200, common.KeyModels{"user": common.User0})
|
|
assert.NoError(t, err)
|
|
}
|