Add tests for edit settings & password

This commit is contained in:
Zoe Roux 2025-04-05 16:40:21 +02:00
parent 31d545530b
commit 8110f7de66
No known key found for this signature in database
3 changed files with 77 additions and 1 deletions

View File

@ -53,7 +53,7 @@ type Validator struct {
func (v *Validator) Validate(i any) error {
if err := v.validator.Struct(i); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
return echo.NewHTTPError(http.StatusUnprocessableEntity, err.Error())
}
return nil
}

View File

@ -0,0 +1,40 @@
POST {{host}}/users
{
"username": "edit-password",
"password": "password-login-user",
"email": "invalid-password-user@zoriya.dev"
}
HTTP 201
[Captures]
first_token: jsonpath "$.token"
POST {{host}}/sessions
{
"login": "edit-password",
"password": "password-login-user"
}
HTTP 201
[Captures]
token: jsonpath "$.token"
GET {{host}}/jwt
Authorization: Bearer {{token}}
HTTP 200
[Captures]
jwt: jsonpath "$.token"
PATCH {{host}}/users/me/password
Authorization: Bearer {{jwt}}
{
"password": "new-password"
}
HTTP 204
# Invalid password login
POST {{host}}/jwt
Authorization: Bearer {{first_token}}
HTTP 403
DELETE {{host}}/users/me
Authorization: Bearer {{jwt}}
HTTP 200

View File

@ -0,0 +1,36 @@
POST {{host}}/users
{
"username": "edit-settings",
"password": "password-login-user",
"email": "edit-settings@zoriya.dev"
}
HTTP 201
[Captures]
token: jsonpath "$.token"
GET {{host}}/jwt
Authorization: Bearer {{token}}
HTTP 200
[Captures]
jwt: jsonpath "$.token"
PATCH {{host}}/users/me
Authorization: Bearer {{jwt}}
{
"claims": {
"preferOriginal": true
}
}
HTTP 200
[Asserts]
jsonpath ".claims.preferOriginal" == true
jsonpath ".username" == "edit-settings"
# Invalid password login
POST {{host}}/jwt
Authorization: Bearer {{token}}
HTTP 403
DELETE {{host}}/users/me
Authorization: Bearer {{jwt}}
HTTP 200