mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-23 23:55:02 +01:00
Add test for provided login and password
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user