all repos

onasty @ e9424c1352208a66473831b952a053125d66f5ca

a one-time notes service
2 files changed, 26 insertions(+), 32 deletions(-)
refactor: use e.randomEmail() everywhere i need an email (#200)

* refactor: use e.randomEmail() everywhere i need an email

* also use random passwords
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)
M e2e/apiv1_notes_authorized_test.go

@@ -7,7 +7,7 @@ "time"

) func (e *AppTestSuite) TestNoteV1_Create_authorized() { - uid, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + uid, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) httpResp := e.httpRequest( http.MethodPost, "/api/v1/note",

@@ -28,7 +28,7 @@ e.Equal(dbNote.ID.String(), dbNoteAuthor.noteID.String())

} func (e *AppTestSuite) TestNoteV1_Delete() { - _, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + _, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) httpResp := e.httpRequest( http.MethodPost, "/api/v1/note",

@@ -64,7 +64,7 @@ KeepBeforeExpiration bool `json:"keep_before_expiration"`

} func (e *AppTestSuite) TestNoteV1_updateExpirationTime() { - _, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + _, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) httpResp := e.httpRequest( http.MethodPost, "/api/v1/note",

@@ -100,7 +100,7 @@ e.Equal(patchTime.Unix(), dbNote.ExpiresAt.Unix())

} func (e *AppTestSuite) TestNoteV1_updateExpirationTime_notFound() { - _, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + _, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) httpResp := e.httpRequest( http.MethodPatch, "/api/v1/note/"+e.uuid(),

@@ -119,7 +119,7 @@ Password string `json:"password"`

} func (e *AppTestSuite) TestNoteV1_UpdatePassword() { - _, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + _, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) httpResp := e.httpRequest( http.MethodPost, "/api/v1/note",

@@ -157,7 +157,7 @@ e.require.NoError(err)

} func (e *AppTestSuite) TestNoteV1_UpdatePassword_notFound() { - _, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + _, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) httpResp := e.httpRequest( http.MethodPatch, "/api/v1/note/"+e.uuid()+"/password",

@@ -171,7 +171,7 @@ e.Equal(httpResp.Code, http.StatusNotFound)

} func (e *AppTestSuite) TestNoteV1_UpdatePassword_passwordNotProvided() { - _, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + _, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) httpResp := e.httpRequest( http.MethodPost, "/api/v1/note",

@@ -224,7 +224,7 @@ {slug: e.uuid(), content: e.uuid(), read: false},

{slug: e.uuid(), content: e.uuid(), read: false}, } - _, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + _, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) // create notes for _, ni := range notesInfo {

@@ -273,7 +273,7 @@ {slug: e.uuid(), content: e.uuid()},

{slug: e.uuid(), content: e.uuid()}, } - _, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + _, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) // create few notes for _, ni := range notesInfo {

@@ -333,7 +333,7 @@ slices.Clone(notesInfo),

func(n notesTestData) bool { return n.read }), ) - _, toks := e.createAndSingIn(e.uuid()+"@test.com", "password") + _, toks := e.createAndSingIn(e.randomEmail(), e.uuid()) // create notes for _, ni := range notesInfo {