Feature: integration testing

Add integration tests with testify/suite. Moved some structs
outside of controller funcs so we can re-use them in the testing
package. Add CI workflow for running tests on every push.
This commit is contained in:
kiwiidb
2022-02-01 11:47:11 +01:00
parent 89a924bd30
commit 1ae5df6b8c
6 changed files with 178 additions and 29 deletions

View File

@@ -19,20 +19,24 @@ func NewAuthController(svc *service.LndhubService) *AuthController {
}
}
type AuthRequestBody struct {
Login string `json:"login"`
Password string `json:"password"`
RefreshToken string `json:"refresh_token"`
}
type AuthResponseBody struct {
RefreshToken string `json:"refresh_token"`
AccessToken string `json:"access_token"`
}
// Auth : Auth Controller
func (controller *AuthController) Auth(c echo.Context) error {
type RequestBody struct {
Login string `json:"login"`
Password string `json:"password"`
RefreshToken string `json:"refresh_token"`
}
var body RequestBody
var body AuthRequestBody
if err := c.Bind(&body); err != nil {
return err
}
if err := c.Validate(&body); err != nil {
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
}
@@ -42,8 +46,8 @@ func (controller *AuthController) Auth(c echo.Context) error {
return err
}
return c.JSON(http.StatusOK, echo.Map{
"refresh_token": refreshToken,
"access_token": accessToken,
return c.JSON(http.StatusOK, &AuthResponseBody{
RefreshToken: refreshToken,
AccessToken: accessToken,
})
}