Add test for provided login and password

This commit is contained in:
Stefan Kostic
2022-02-09 22:59:11 +01:00
parent 80a4d4f20c
commit 06e4257aaa

View File

@@ -55,7 +55,33 @@ func (suite *CreateUserTestSuite) TestCreate() {
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(&responseBody))
assert.NotEmpty(suite.T(), responseBody.Login)
assert.NotEmpty(suite.T(), responseBody.Password)
fmt.Printf("Sucessfully created user with login %ss\n", responseBody.Login)
fmt.Printf("Sucessfully created user with login %s\n", responseBody.Login)
}
}
func (suite *CreateUserTestSuite) TestCreateWithProvidedLoginAndPassword() {
e := echo.New()
e.HTTPErrorHandler = responses.HTTPErrorHandler
e.Validator = &lib.CustomValidator{Validator: validator.New()}
var buf bytes.Buffer
const testLogin = "test login"
const testPassword = "test password"
json.NewEncoder(&buf).Encode(&controllers.AuthRequestBody{
Login: testLogin,
Password: testPassword,
})
req := httptest.NewRequest(http.MethodPost, "/create", &buf)
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
controller := controllers.NewCreateUserController(suite.Service)
responseBody := controllers.CreateUserResponseBody{}
if assert.NoError(suite.T(), controller.CreateUser(c)) {
assert.Equal(suite.T(), http.StatusOK, rec.Code)
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(&responseBody))
assert.Equal(suite.T(), testLogin, responseBody.Login)
assert.Equal(suite.T(), testPassword, responseBody.Password)
fmt.Printf("Sucessfully created user with login %s\n", responseBody.Login)
}
}