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

- The function must return the token and an error (string, error). In case of an error the token is going to be an empty string. The assertion for the error __must__ be executed in the body of the test. The utility functions __must not__ panic. All of the tests must use this function in the future.
40 lines
959 B
Go
40 lines
959 B
Go
package user
|
|
|
|
import (
|
|
"encoding/json"
|
|
"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) {
|
|
|
|
myUsers := []common.User{common.User0, common.UserA, common.UserB}
|
|
msgUsers := common.ResponseMsgUsers{Users: myUsers}
|
|
|
|
db := common.DummyInitDB()
|
|
defer db.Close()
|
|
common.DummyPopulateDB(db)
|
|
|
|
router := gin.Default()
|
|
api := router.Group("/api")
|
|
|
|
VisitorAuthenticate(api.Group("/authenticate"))
|
|
api.Use(Authentication(true))
|
|
RegisterUserEndpoints(api.Group("/users"))
|
|
|
|
credjson, _ := json.Marshal(common.CredAdmin)
|
|
msgUsersjson, _ := json.Marshal(msgUsers)
|
|
|
|
token, err := common.NewAuthenticateForTest(router,
|
|
"/api/authenticate", "POST", credjson, 200)
|
|
assert.NoError(t, err)
|
|
|
|
// test GET user/
|
|
err = common.NewTestEndpoint(router, token, "/api/users", "GET",
|
|
nil, 200, msgUsersjson)
|
|
assert.NoError(t, err)
|
|
}
|