@@ -58,7 +58,7 @@ func Test_usecase_CreateUser(t *testing.T) {
58
58
59
59
crypto := app_crypto .NewCrypto (KeyUnitTest )
60
60
appJwt := app_jwt .NewJWT (config.JWTConfig {Key : KeyUnitTest , Expired : 60 , Label : "XXXX" })
61
- ctx := context .Background ()
61
+ ctx := context .TODO ()
62
62
repo := mocks .NewMockRepository (ctrl )
63
63
uc := usecase .NewUseCase (
64
64
repo ,
@@ -74,10 +74,10 @@ func Test_usecase_CreateUser(t *testing.T) {
74
74
}
75
75
76
76
t .Run ("positive_case_create_user" , func (t * testing.T ) {
77
- repo .EXPECT ().IsUserExist (ctx , newUser .Email ).Return (false )
77
+ repo .EXPECT ().IsUserExist (gomock . Any () , newUser .Email ).Return (false )
78
78
79
79
repo .EXPECT ().
80
- SaveNewUser (ctx ,
80
+ SaveNewUser (gomock . Any () ,
81
81
createUserMatcher (
82
82
entities.User {
83
83
Fullname : newUser .FullName ,
@@ -94,18 +94,18 @@ func Test_usecase_CreateUser(t *testing.T) {
94
94
})
95
95
96
96
t .Run ("negative_email_already_use" , func (t * testing.T ) {
97
- repo .EXPECT ().IsUserExist (ctx , newUser .Email ).Return (true )
97
+ repo .EXPECT ().IsUserExist (gomock . Any () , newUser .Email ).Return (true )
98
98
99
99
userID , err := uc .Create (ctx , newUser )
100
100
require .EqualError (t , apperror .ErrEmailAlreadyExist , err .Error ())
101
101
require .Equal (t , userID , int64 (0 ))
102
102
})
103
103
104
104
t .Run ("negative_case_create_user_error_repo" , func (t * testing.T ) {
105
- repo .EXPECT ().IsUserExist (ctx , newUser .Email ).Return (false )
105
+ repo .EXPECT ().IsUserExist (gomock . Any () , newUser .Email ).Return (false )
106
106
107
107
repo .EXPECT ().
108
- SaveNewUser (ctx ,
108
+ SaveNewUser (gomock . Any () ,
109
109
createUserMatcher (
110
110
entities.User {
111
111
Fullname : "fullname" ,
@@ -146,11 +146,11 @@ func Test_usecase_UpdateUserStatus(t *testing.T) {
146
146
147
147
t .Run ("positive_case_UpdateUserStatus" , func (t * testing.T ) {
148
148
repo .EXPECT ().
149
- GetUserByID (ctx , args .UserID , gomock .Any ()).
149
+ GetUserByID (gomock . Any () , args .UserID , gomock .Any ()).
150
150
Return (entities.User {UserID : 1 , IsActive : true }, nil )
151
151
152
152
repo .EXPECT ().
153
- UpdateUserStatusByID (ctx , gomock .Any ()).
153
+ UpdateUserStatusByID (gomock . Any () , gomock .Any ()).
154
154
Return (nil )
155
155
156
156
err := uc .UpdateStatus (ctx , args )
@@ -159,7 +159,7 @@ func Test_usecase_UpdateUserStatus(t *testing.T) {
159
159
160
160
t .Run ("negative_case_UpdateUserStatus_GetUserByID_err" , func (t * testing.T ) {
161
161
repo .EXPECT ().
162
- GetUserByID (ctx , args .UserID , gomock .Any ()).
162
+ GetUserByID (gomock . Any () , args .UserID , gomock .Any ()).
163
163
Return (entities.User {}, errors .New ("something errors" ))
164
164
165
165
err := uc .UpdateStatus (ctx , args )
@@ -168,11 +168,11 @@ func Test_usecase_UpdateUserStatus(t *testing.T) {
168
168
169
169
t .Run ("negative_case_UpdateUserStatus_err" , func (t * testing.T ) {
170
170
repo .EXPECT ().
171
- GetUserByID (ctx , args .UserID , gomock .Any ()).
171
+ GetUserByID (gomock . Any () , args .UserID , gomock .Any ()).
172
172
Return (entities.User {UserID : 1 , IsActive : true }, nil )
173
173
174
174
repo .EXPECT ().
175
- UpdateUserStatusByID (ctx , gomock .Any ()).
175
+ UpdateUserStatusByID (gomock . Any () , gomock .Any ()).
176
176
Return (errors .New ("there was error" ))
177
177
178
178
err := uc .UpdateStatus (ctx , args )
@@ -208,15 +208,15 @@ func Test_usecase_Detail(t *testing.T) {
208
208
}
209
209
210
210
t .Run ("detail_positive" , func (t * testing.T ) {
211
- repo .EXPECT ().GetUserByID (ctx , id ).Return (returnedDetail , nil )
211
+ repo .EXPECT ().GetUserByID (gomock . Any () , id ).Return (returnedDetail , nil )
212
212
213
213
detail , err := uc .Detail (ctx , id )
214
214
require .NoError (t , err )
215
215
require .Equal (t , detail , entities .NewUserDetail (returnedDetail ))
216
216
})
217
217
218
218
t .Run ("detail_negative_failed_query_detail" , func (t * testing.T ) {
219
- repo .EXPECT ().GetUserByID (ctx , id ).Return (entities.User {}, sql .ErrNoRows )
219
+ repo .EXPECT ().GetUserByID (gomock . Any () , id ).Return (entities.User {}, sql .ErrNoRows )
220
220
221
221
detail , err := uc .Detail (ctx , id )
222
222
require .EqualError (t , err , sql .ErrNoRows .Error ())
@@ -251,7 +251,7 @@ func Test_usecase_Login(t *testing.T) {
251
251
}
252
252
253
253
t .Run ("login_positive" , func (t * testing.T ) {
254
- repo .EXPECT ().GetUserByEmail (ctx , email ).Return (returnedUser , nil )
254
+ repo .EXPECT ().GetUserByEmail (gomock . Any () , email ).Return (returnedUser , nil )
255
255
256
256
authData , err := uc .Login (ctx , dtos.UserLoginRequest {Email : email , Password : password })
257
257
require .NoError (t , err )
@@ -260,7 +260,7 @@ func Test_usecase_Login(t *testing.T) {
260
260
})
261
261
262
262
t .Run ("login_negative_invalid_password" , func (t * testing.T ) {
263
- repo .EXPECT ().GetUserByEmail (ctx , email ).Return (returnedUser , nil )
263
+ repo .EXPECT ().GetUserByEmail (gomock . Any () , email ).Return (returnedUser , nil )
264
264
265
265
authData , err := uc .Login (ctx , dtos.UserLoginRequest {Email : email , Password : "testingpwd" })
266
266
require .EqualError (t , apperror .ErrInvalidPassword , err .Error ())
@@ -269,7 +269,7 @@ func Test_usecase_Login(t *testing.T) {
269
269
})
270
270
271
271
t .Run ("login_negative_failed_query_email" , func (t * testing.T ) {
272
- repo .EXPECT ().GetUserByEmail (ctx , email ).Return (entities.User {}, sql .ErrNoRows )
272
+ repo .EXPECT ().GetUserByEmail (gomock . Any () , email ).Return (entities.User {}, sql .ErrNoRows )
273
273
274
274
authData , err := uc .Login (ctx , dtos.UserLoginRequest {Email : email , Password : password })
275
275
require .EqualError (t , err , sql .ErrNoRows .Error ())
0 commit comments