2 files changed,
26 insertions(+),
32 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed by:
GitHub
noreply@github.com
Committed at:
2025-08-31 19:15:21 +0300
Parent:
eb4c605
M
e2e/apiv1_auth_test.go
@@ -18,8 +18,7 @@ Password string `json:"password"`
} func (e *AppTestSuite) TestAuthV1_SignUP() { - email := e.uuid() + "test@test.com" - password := "password" + email, password := e.randomEmail(), "password" httpResp := e.httpRequest( http.MethodPost,@@ -47,7 +46,7 @@ password string
}{ {name: "all fields empty", email: "", password: ""}, {name: "non valid email", email: "email", password: "password"}, - {name: "non valid password", email: "test@test.com", password: "12345"}, + {name: "non valid password", email: e.randomEmail(), password: "12345"}, } for _, t := range tests { httpResp := e.httpRequest(@@ -200,11 +199,9 @@ e.Equal(parsedToken.UserID, uid.String())
} func (e *AppTestSuite) TestAuthV1_SignIn_wrong() { - password := "password" - email := e.uuid() + "@test.com" - e.insertUser(email, "password", true) + email, unactivatedEmail, password := e.randomEmail(), e.randomEmail(), e.uuid() - unactivatedEmail := e.uuid() + "@test.com" + e.insertUser(email, password, true) e.insertUser(unactivatedEmail, password, false) //exhaustruct:ignore@@ -228,7 +225,7 @@ },
{ name: "wrong email", email: "wrong@email.com", - password: password, + password: e.uuid(), expectedCode: http.StatusBadRequest, expectedMsg: models.ErrUserWrongCredentials.Error(), },@@ -267,7 +264,7 @@ RefreshToken string `json:"refresh_token"`
} func (e *AppTestSuite) TestAuthV1_RefreshTokens() { - uid, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + uid, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) httpResp := e.httpRequest( http.MethodPost, "/api/v1/auth/refresh-tokens",@@ -304,7 +301,7 @@ RefreshToken string `json:"refresh_token"`
} func (e *AppTestSuite) TestAuthV1_Logout() { - uid, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + uid, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) sessionDB := e.getLastSessionByUserID(uid) e.NotEmpty(sessionDB.RefreshToken)@@ -324,7 +321,7 @@ e.Empty(sessionDB.RefreshToken)
} func (e *AppTestSuite) TestAuthV1_LogoutAll() { - uid, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + uid, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) var res int query := "select count(*) from sessions where user_id = $1"@@ -347,8 +344,7 @@ NewPassword string `json:"new_password"`
} func (e *AppTestSuite) TestAuthV1_ChangePassword() { - oldPassword, newPassword := e.uuid(), e.uuid() - email := e.uuid() + "@test.com" + email, oldPassword, newPassword := e.randomEmail(), e.uuid(), e.uuid() _, toks := e.createAndSingIn(email, oldPassword) httpResp := e.httpRequest(@@ -368,10 +364,8 @@ e.NoError(e.hasher.Compare(userDB.Password, newPassword))
} func (e *AppTestSuite) TestAuthV1_ChangePassword_wrongPassword() { - password := e.uuid() - newPassword := e.uuid() - email := e.uuid() + "@test.com" - _, toks := e.createAndSingIn(email, password) + email, oldPassword, newPassword := e.randomEmail(), e.uuid(), e.uuid() + _, toks := e.createAndSingIn(email, oldPassword) httpResp := e.httpRequest( http.MethodPost,@@ -405,8 +399,8 @@ }
) func (e *AppTestSuite) TestAuthV1_ResetPassword() { - email := e.uuid() + "@test.com" - uid, _ := e.createAndSingIn(email, "password") + email := e.randomEmail() + uid, _ := e.createAndSingIn(email, e.uuid()) httpResp := e.httpRequest( http.MethodPost,@@ -441,7 +435,7 @@ e.NotEmpty(token.UsedAt)
} func (e *AppTestSuite) TestAuthV1_ResetPassword_nonExistentUser() { - _, _ = e.createAndSingIn(e.uuid()+"@test.com", "password") + _, _ = e.createAndSingIn(e.randomEmail(), e.uuid()) httpResp := e.httpRequest( http.MethodPost, "/api/v1/auth/reset-password",@@ -516,8 +510,8 @@ NotesCreated int `json:"notes_created"`
} func (e *AppTestSuite) TestApiV1_getMe() { - email := e.uuid() + "@test.com" - uid, toks := e.createAndSingIn(email, "password") + email := e.randomEmail() + uid, toks := e.createAndSingIn(email, e.uuid()) httpResp := e.httpRequest(http.MethodGet, "/api/v1/me", nil, toks.AccessToken)