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
        18
         }

      
        19
        19
         

      
        20
        20
         func (e *AppTestSuite) TestAuthV1_SignUP() {

      
        21
        
        -	email := e.uuid() + "test@test.com"

      
        22
        
        -	password := "password"

      
        
        21
        +	email, password := e.randomEmail(), "password"

      
        23
        22
         

      
        24
        23
         	httpResp := e.httpRequest(

      
        25
        24
         		http.MethodPost,

      ···
        47
        46
         	}{

      
        48
        47
         		{name: "all fields empty", email: "", password: ""},

      
        49
        48
         		{name: "non valid email", email: "email", password: "password"},

      
        50
        
        -		{name: "non valid password", email: "test@test.com", password: "12345"},

      
        
        49
        +		{name: "non valid password", email: e.randomEmail(), password: "12345"},

      
        51
        50
         	}

      
        52
        51
         	for _, t := range tests {

      
        53
        52
         		httpResp := e.httpRequest(

      ···
        200
        199
         }

      
        201
        200
         

      
        202
        201
         func (e *AppTestSuite) TestAuthV1_SignIn_wrong() {

      
        203
        
        -	password := "password"

      
        204
        
        -	email := e.uuid() + "@test.com"

      
        205
        
        -	e.insertUser(email, "password", true)

      
        
        202
        +	email, unactivatedEmail, password := e.randomEmail(), e.randomEmail(), e.uuid()

      
        206
        203
         

      
        207
        
        -	unactivatedEmail := e.uuid() + "@test.com"

      
        
        204
        +	e.insertUser(email, password, true)

      
        208
        205
         	e.insertUser(unactivatedEmail, password, false)

      
        209
        206
         

      
        210
        207
         	//exhaustruct:ignore

      ···
        228
        225
         		{

      
        229
        226
         			name:         "wrong email",

      
        230
        227
         			email:        "wrong@email.com",

      
        231
        
        -			password:     password,

      
        
        228
        +			password:     e.uuid(),

      
        232
        229
         			expectedCode: http.StatusBadRequest,

      
        233
        230
         			expectedMsg:  models.ErrUserWrongCredentials.Error(),

      
        234
        231
         		},

      ···
        267
        264
         }

      
        268
        265
         

      
        269
        266
         func (e *AppTestSuite) TestAuthV1_RefreshTokens() {

      
        270
        
        -	uid, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        267
        +	uid, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        271
        268
         	httpResp := e.httpRequest(

      
        272
        269
         		http.MethodPost,

      
        273
        270
         		"/api/v1/auth/refresh-tokens",

      ···
        304
        301
         }

      
        305
        302
         

      
        306
        303
         func (e *AppTestSuite) TestAuthV1_Logout() {

      
        307
        
        -	uid, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        304
        +	uid, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        308
        305
         

      
        309
        306
         	sessionDB := e.getLastSessionByUserID(uid)

      
        310
        307
         	e.NotEmpty(sessionDB.RefreshToken)

      ···
        324
        321
         }

      
        325
        322
         

      
        326
        323
         func (e *AppTestSuite) TestAuthV1_LogoutAll() {

      
        327
        
        -	uid, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        324
        +	uid, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        328
        325
         

      
        329
        326
         	var res int

      
        330
        327
         	query := "select count(*) from sessions where user_id = $1"

      ···
        347
        344
         }

      
        348
        345
         

      
        349
        346
         func (e *AppTestSuite) TestAuthV1_ChangePassword() {

      
        350
        
        -	oldPassword, newPassword := e.uuid(), e.uuid()

      
        351
        
        -	email := e.uuid() + "@test.com"

      
        
        347
        +	email, oldPassword, newPassword := e.randomEmail(), e.uuid(), e.uuid()

      
        352
        348
         	_, toks := e.createAndSingIn(email, oldPassword)

      
        353
        349
         

      
        354
        350
         	httpResp := e.httpRequest(

      ···
        368
        364
         }

      
        369
        365
         

      
        370
        366
         func (e *AppTestSuite) TestAuthV1_ChangePassword_wrongPassword() {

      
        371
        
        -	password := e.uuid()

      
        372
        
        -	newPassword := e.uuid()

      
        373
        
        -	email := e.uuid() + "@test.com"

      
        374
        
        -	_, toks := e.createAndSingIn(email, password)

      
        
        367
        +	email, oldPassword, newPassword := e.randomEmail(), e.uuid(), e.uuid()

      
        
        368
        +	_, toks := e.createAndSingIn(email, oldPassword)

      
        375
        369
         

      
        376
        370
         	httpResp := e.httpRequest(

      
        377
        371
         		http.MethodPost,

      ···
        405
        399
         )

      
        406
        400
         

      
        407
        401
         func (e *AppTestSuite) TestAuthV1_ResetPassword() {

      
        408
        
        -	email := e.uuid() + "@test.com"

      
        409
        
        -	uid, _ := e.createAndSingIn(email, "password")

      
        
        402
        +	email := e.randomEmail()

      
        
        403
        +	uid, _ := e.createAndSingIn(email, e.uuid())

      
        410
        404
         

      
        411
        405
         	httpResp := e.httpRequest(

      
        412
        406
         		http.MethodPost,

      ···
        441
        435
         }

      
        442
        436
         

      
        443
        437
         func (e *AppTestSuite) TestAuthV1_ResetPassword_nonExistentUser() {

      
        444
        
        -	_, _ = e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        438
        +	_, _ = e.createAndSingIn(e.randomEmail(), e.uuid())

      
        445
        439
         	httpResp := e.httpRequest(

      
        446
        440
         		http.MethodPost,

      
        447
        441
         		"/api/v1/auth/reset-password",

      ···
        516
        510
         }

      
        517
        511
         

      
        518
        512
         func (e *AppTestSuite) TestApiV1_getMe() {

      
        519
        
        -	email := e.uuid() + "@test.com"

      
        520
        
        -	uid, toks := e.createAndSingIn(email, "password")

      
        
        513
        +	email := e.randomEmail()

      
        
        514
        +	uid, toks := e.createAndSingIn(email, e.uuid())

      
        521
        515
         

      
        522
        516
         	httpResp := e.httpRequest(http.MethodGet, "/api/v1/me", nil, toks.AccessToken)

      
        523
        517
         

      
M e2e/apiv1_notes_authorized_test.go
···
        7
        7
         )

      
        8
        8
         

      
        9
        9
         func (e *AppTestSuite) TestNoteV1_Create_authorized() {

      
        10
        
        -	uid, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        10
        +	uid, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        11
        11
         	httpResp := e.httpRequest(

      
        12
        12
         		http.MethodPost,

      
        13
        13
         		"/api/v1/note",

      ···
        28
        28
         }

      
        29
        29
         

      
        30
        30
         func (e *AppTestSuite) TestNoteV1_Delete() {

      
        31
        
        -	_, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        31
        +	_, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        32
        32
         	httpResp := e.httpRequest(

      
        33
        33
         		http.MethodPost,

      
        34
        34
         		"/api/v1/note",

      ···
        64
        64
         }

      
        65
        65
         

      
        66
        66
         func (e *AppTestSuite) TestNoteV1_updateExpirationTime() {

      
        67
        
        -	_, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        67
        +	_, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        68
        68
         	httpResp := e.httpRequest(

      
        69
        69
         		http.MethodPost,

      
        70
        70
         		"/api/v1/note",

      ···
        100
        100
         }

      
        101
        101
         

      
        102
        102
         func (e *AppTestSuite) TestNoteV1_updateExpirationTime_notFound() {

      
        103
        
        -	_, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        103
        +	_, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        104
        104
         	httpResp := e.httpRequest(

      
        105
        105
         		http.MethodPatch,

      
        106
        106
         		"/api/v1/note/"+e.uuid(),

      ···
        119
        119
         }

      
        120
        120
         

      
        121
        121
         func (e *AppTestSuite) TestNoteV1_UpdatePassword() {

      
        122
        
        -	_, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        122
        +	_, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        123
        123
         	httpResp := e.httpRequest(

      
        124
        124
         		http.MethodPost,

      
        125
        125
         		"/api/v1/note",

      ···
        157
        157
         }

      
        158
        158
         

      
        159
        159
         func (e *AppTestSuite) TestNoteV1_UpdatePassword_notFound() {

      
        160
        
        -	_, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        160
        +	_, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        161
        161
         	httpResp := e.httpRequest(

      
        162
        162
         		http.MethodPatch,

      
        163
        163
         		"/api/v1/note/"+e.uuid()+"/password",

      ···
        171
        171
         }

      
        172
        172
         

      
        173
        173
         func (e *AppTestSuite) TestNoteV1_UpdatePassword_passwordNotProvided() {

      
        174
        
        -	_, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        174
        +	_, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        175
        175
         	httpResp := e.httpRequest(

      
        176
        176
         		http.MethodPost,

      
        177
        177
         		"/api/v1/note",

      ···
        224
        224
         		{slug: e.uuid(), content: e.uuid(), read: false},

      
        225
        225
         	}

      
        226
        226
         

      
        227
        
        -	_, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        227
        +	_, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        228
        228
         

      
        229
        229
         	// create notes

      
        230
        230
         	for _, ni := range notesInfo {

      ···
        273
        273
         		{slug: e.uuid(), content: e.uuid()},

      
        274
        274
         	}

      
        275
        275
         

      
        276
        
        -	_, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        276
        +	_, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        277
        277
         

      
        278
        278
         	// create few notes

      
        279
        279
         	for _, ni := range notesInfo {

      ···
        333
        333
         			func(n notesTestData) bool { return n.read }),

      
        334
        334
         	)

      
        335
        335
         

      
        336
        
        -	_, toks := e.createAndSingIn(e.uuid()+"@test.com", "password")

      
        
        336
        +	_, toks := e.createAndSingIn(e.randomEmail(), e.uuid())

      
        337
        337
         

      
        338
        338
         	// create notes

      
        339
        339
         	for _, ni := range notesInfo {