@Test public void testRequestPasswordReset() { when(mailClient.send(any(EmailRequest.class))).thenReturn(BaseResponse.builder().message("email sent").build()); String name = "testAccount"; String email = "test@staffjoy.xyz"; String phoneNumber = "18001801236"; CreateAccountRequest createAccountRequest = CreateAccountRequest.builder() .name(name) .email(email) .phoneNumber(phoneNumber) .build(); GenericAccountResponse genericAccountResponse = accountClient.createAccount(AuthConstant.AUTHORIZATION_WWW_SERVICE, createAccountRequest); assertThat(genericAccountResponse.isSuccess()).isTrue(); AccountDto accountDto = genericAccountResponse.getAccount(); PasswordResetRequest passwordResetRequest = PasswordResetRequest.builder() .email(email) .build(); BaseResponse baseResponse = accountClient.requestPasswordReset(AuthConstant.AUTHORIZATION_WWW_SERVICE, passwordResetRequest); assertThat(baseResponse.isSuccess()).isTrue(); String subject = "Activate your Staffjoy account"; String externalApex = "staffjoy-v2.local"; ArgumentCaptor<EmailRequest> argument = ArgumentCaptor.forClass(EmailRequest.class); verify(mailClient, times(2)).send(argument.capture()); EmailRequest emailRequest = argument.getAllValues().get(1); log.info(emailRequest.toString()); assertThat(emailRequest.getTo()).isEqualTo(email); assertThat(emailRequest.getSubject()).isEqualTo(subject); assertThat(emailRequest.getName()).isEqualTo(name); assertThat(StringUtils.countMatches(emailRequest.getHtmlBody(), "http: assertThat(StringUtils.countMatches(emailRequest.getHtmlBody(), name)).isEqualTo(1); assertThat(emailRequest.getHtmlBody()).startsWith("<div><p>Hi"); accountDto.setConfirmedAndActive(true); genericAccountResponse = accountClient.updateAccount(AuthConstant.AUTHORIZATION_WWW_SERVICE, accountDto); assertThat(genericAccountResponse.isSuccess()).isTrue(); passwordResetRequest = PasswordResetRequest.builder() .email(email) .build(); baseResponse = accountClient.requestPasswordReset(AuthConstant.AUTHORIZATION_WWW_SERVICE, passwordResetRequest); log.info(baseResponse.toString()); assertThat(baseResponse.isSuccess()).isTrue(); subject = "Reset your Staffjoy password"; argument = ArgumentCaptor.forClass(EmailRequest.class); verify(mailClient, times(3)).send(argument.capture()); emailRequest = argument.getAllValues().get(2); log.info(emailRequest.toString()); assertThat(emailRequest.getTo()).isEqualTo(email); assertThat(emailRequest.getSubject()).isEqualTo(subject); assertThat(emailRequest.getName()).isEqualTo(name); assertThat(StringUtils.countMatches(emailRequest.getHtmlBody(), "http: assertThat(emailRequest.getHtmlBody()).startsWith("<div>We received a request to reset the password on your account."); }
@PostMapping(path = "/request_password_reset") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public BaseResponse requestPasswordReset(@RequestBody @Valid PasswordResetRequest request) { accountService.requestPasswordReset(request.getEmail()); BaseResponse baseResponse = new BaseResponse(); baseResponse.setMessage("password reset requested"); return baseResponse; }
AccountController { @PostMapping(path = "/request_password_reset") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public BaseResponse requestPasswordReset(@RequestBody @Valid PasswordResetRequest request) { accountService.requestPasswordReset(request.getEmail()); BaseResponse baseResponse = new BaseResponse(); baseResponse.setMessage("password reset requested"); return baseResponse; } }
AccountController { @PostMapping(path = "/request_password_reset") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public BaseResponse requestPasswordReset(@RequestBody @Valid PasswordResetRequest request) { accountService.requestPasswordReset(request.getEmail()); BaseResponse baseResponse = new BaseResponse(); baseResponse.setMessage("password reset requested"); return baseResponse; }  }
AccountController { @PostMapping(path = "/request_password_reset") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public BaseResponse requestPasswordReset(@RequestBody @Valid PasswordResetRequest request) { accountService.requestPasswordReset(request.getEmail()); BaseResponse baseResponse = new BaseResponse(); baseResponse.setMessage("password reset requested"); return baseResponse; }  @PostMapping(path = "/get_or_create") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE }) GenericAccountResponse getOrCreate(@RequestBody @Valid GetOrCreateRequest request); @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE }) GenericAccountResponse createAccount(@RequestBody @Valid CreateAccountRequest request); @GetMapping(path = "/get_account_by_phonenumber") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE }) GenericAccountResponse getAccountByPhonenumber(@RequestParam @PhoneNumber String phoneNumber); @GetMapping(path = "/list") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER }) ListAccountResponse listAccounts(@RequestParam int offset, @RequestParam @Min(0) int limit); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE, AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_SUPERPOWERS_SERVICE }) GenericAccountResponse getAccount(@RequestParam @NotBlank String userId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_SUPERPOWERS_SERVICE }) GenericAccountResponse updateAccount(@RequestBody @Valid AccountDto newAccountDto); @PutMapping(path = "/update_password") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse updatePassword(@RequestBody @Valid UpdatePasswordRequest request); @PostMapping(path = "/verify_password") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericAccountResponse verifyPassword(@RequestBody @Valid VerifyPasswordRequest request); @PostMapping(path = "/request_password_reset") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse requestPasswordReset(@RequestBody @Valid PasswordResetRequest request); @PostMapping(path = "/request_email_change") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse requestEmailChange(@RequestBody @Valid EmailChangeRequest request); @PostMapping(path = "/change_email") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse changeEmail(@RequestBody @Valid EmailConfirmation request); @PostMapping(path = "/track_event") BaseResponse trackEvent(@RequestBody @Valid TrackEventRequest request); @PostMapping(path = "/sync_user") BaseResponse syncUser(@RequestBody @Valid SyncUserRequest request); }
AccountController { @PostMapping(path = "/request_password_reset") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public BaseResponse requestPasswordReset(@RequestBody @Valid PasswordResetRequest request) { accountService.requestPasswordReset(request.getEmail()); BaseResponse baseResponse = new BaseResponse(); baseResponse.setMessage("password reset requested"); return baseResponse; }  @PostMapping(path = "/get_or_create") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE }) GenericAccountResponse getOrCreate(@RequestBody @Valid GetOrCreateRequest request); @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE }) GenericAccountResponse createAccount(@RequestBody @Valid CreateAccountRequest request); @GetMapping(path = "/get_account_by_phonenumber") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE }) GenericAccountResponse getAccountByPhonenumber(@RequestParam @PhoneNumber String phoneNumber); @GetMapping(path = "/list") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER }) ListAccountResponse listAccounts(@RequestParam int offset, @RequestParam @Min(0) int limit); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE, AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_SUPERPOWERS_SERVICE }) GenericAccountResponse getAccount(@RequestParam @NotBlank String userId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_COMPANY_SERVICE, AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_SUPERPOWERS_SERVICE }) GenericAccountResponse updateAccount(@RequestBody @Valid AccountDto newAccountDto); @PutMapping(path = "/update_password") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse updatePassword(@RequestBody @Valid UpdatePasswordRequest request); @PostMapping(path = "/verify_password") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericAccountResponse verifyPassword(@RequestBody @Valid VerifyPasswordRequest request); @PostMapping(path = "/request_password_reset") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse requestPasswordReset(@RequestBody @Valid PasswordResetRequest request); @PostMapping(path = "/request_email_change") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse requestEmailChange(@RequestBody @Valid EmailChangeRequest request); @PostMapping(path = "/change_email") @Authorize(value = { AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse changeEmail(@RequestBody @Valid EmailConfirmation request); @PostMapping(path = "/track_event") BaseResponse trackEvent(@RequestBody @Valid TrackEventRequest request); @PostMapping(path = "/sync_user") BaseResponse syncUser(@RequestBody @Valid SyncUserRequest request);  }