Created
May 9, 2022 13:35
-
-
Save DecodeWorms/6f47af3af4572cb999a90d944a00b38a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestUserVerifyUserAccount(t *testing.T) { | |
t.Parallel() | |
var initCtx = &gin.Context{} | |
//logger := log.WithFields(map[string]interface{}{}) | |
reqId := generator.GenerateRandomString(20) | |
initCtx.Set(utils.RequestID, reqId) | |
ctrl := gomock.NewController(t) | |
defer ctrl.Finish() | |
mockUserService := mocks.NewMockUserService(ctrl) | |
mockConfig := flags.Configuration{} | |
// mockEmail := mocks.NewMockSender(ctrl) | |
handler := NewUserHandler( | |
mockConfig, | |
nil, | |
mockUserService, | |
nil, | |
nil, | |
nil, | |
nil, | |
nil, | |
nil, | |
nil, | |
nil, | |
nil, | |
) | |
t.Run("should handle an empty pin request", func(t *testing.T) { | |
pin := "" | |
mockUserService.EXPECT().UserByPIN(initCtx, pin).Return(nil, gorm.ErrRecordNotFound).Times(1) | |
_, err := handler.VerifyUserAccount(initCtx, pin, nil) | |
assert.Error(t, err) | |
assert.Equal(t, errors.StatusBadRequest, err.Code()) | |
}) | |
t.Run("should handle a valid pin", func(t *testing.T) { | |
pin := "543210" | |
input := models.NewUserData{ | |
Title: "Mr", | |
Email: "[email protected]", | |
FirstName: "Joe", | |
LastName: "Doe", | |
PhoneNumber: "0900000001", | |
Password: "password", | |
} | |
pass, err := password.NewPasswordHash(input.Password) | |
assert.Nil(t, err) | |
userResp := &models.User{ | |
Counter: 1, | |
ID: "3b9b5ea0-34f1-48d0-be98-84e03baee982", | |
Title: input.Title, | |
Email: input.Email, | |
FirstName: input.FirstName, | |
LastName: input.LastName, | |
PhoneNumber: input.PhoneNumber, | |
Password: pass, | |
} | |
var w *models.User | |
mockUserService.EXPECT().UserByPIN(initCtx, pin).Return(userResp, nil).Times(1) | |
mockUserService.EXPECT().ConfirmRegistration(initCtx, userResp.Email).Return(w, nil).Times(1) | |
res, _ := handler.VerifyUserAccount(initCtx, pin, nil) | |
assert.Nil(t, nil) | |
assert.Equal(t, w, res) | |
}) | |
} | |
Error infor | |
2022/05/09 13:49:01 logrus.log has been created or opened for logging: logrus.log | |
2022/05/09 13:49:01 error creating file: mkdir logrus.log: file exists | |
=== RUN TestUserVerifyUserAccount | |
=== PAUSE TestUserVerifyUserAccount | |
=== CONT TestUserVerifyUserAccount | |
=== RUN TestUserVerifyUserAccount/should_handle_an_empty_pin_request | |
=== RUN TestUserVerifyUserAccount/should_handle_a_valid_pin | |
=== CONT TestUserVerifyUserAccount | |
/Users/Oluwashola/go/src/treasure-core-api/features/account/controller.go:269: missing call(s) to *mocks.MockUserService.ConfirmRegistration(is equal to &{{<nil> 0 0} <nil> <nil> [] [] 0 <nil> {{0 0} 0 0 0 0} map[request_id:52fdfc072182654f163f5f0f9a621d729566c74d] [] map[] map[] 0} (*gin.Context), is equal to [email protected] (string)) /Users/Oluwashola/go/src/treasure-core-api/features/account/user_test.go:231 | |
/Users/Oluwashola/go/src/treasure-core-api/features/account/controller.go:269: aborting test due to missing call(s) | |
--- FAIL: TestUserVerifyUserAccount (0.09s) | |
--- PASS: TestUserVerifyUserAccount/should_handle_an_empty_pin_request (0.00s) | |
--- PASS: TestUserVerifyUserAccount/should_handle_a_valid_pin (0.09s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment