@Test public void testUpdateAccount() { when(mailClient.send(any(EmailRequest.class))).thenReturn(BaseResponse.builder().message("email sent").build()); when(botClient.sendSmsGreeting(any(GreetingRequest.class))).thenReturn(BaseResponse.builder().message("sms sent").build()); String name = "testAccount001"; String email = "test001@staffjoy.xyz"; String phoneNumber = "18001801236"; String subject = "Activate your Staffjoy account"; 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(); accountDto.setName("testAccountUpdate"); accountDto.setConfirmedAndActive(true); accountDto.setPhoneNumber("18001801237"); GenericAccountResponse genericAccountResponse1 = accountClient.updateAccount(AuthConstant.AUTHORIZATION_WWW_SERVICE, accountDto); log.info(genericAccountResponse1.toString()); assertThat(genericAccountResponse1.isSuccess()).isTrue(); AccountDto updatedAccountDto = genericAccountResponse1.getAccount(); assertThat(updatedAccountDto).isEqualTo(accountDto); ArgumentCaptor<GreetingRequest> argument = ArgumentCaptor.forClass(GreetingRequest.class); verify(botClient, times(1)).sendSmsGreeting(argument.capture()); GreetingRequest greetingRequest = argument.getValue(); assertThat(greetingRequest.getUserId()).isEqualTo(accountDto.getId()); }
@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 }) public GenericAccountResponse updateAccount(@RequestBody @Valid AccountDto newAccountDto) { this.validateAuthenticatedUser(newAccountDto.getId()); this.validateEnv(); AccountDto accountDto = accountService.update(newAccountDto); GenericAccountResponse genericAccountResponse = new GenericAccountResponse(accountDto); return genericAccountResponse; }
AccountController { @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 }) public GenericAccountResponse updateAccount(@RequestBody @Valid AccountDto newAccountDto) { this.validateAuthenticatedUser(newAccountDto.getId()); this.validateEnv(); AccountDto accountDto = accountService.update(newAccountDto); GenericAccountResponse genericAccountResponse = new GenericAccountResponse(accountDto); return genericAccountResponse; } }
AccountController { @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 }) public GenericAccountResponse updateAccount(@RequestBody @Valid AccountDto newAccountDto) { this.validateAuthenticatedUser(newAccountDto.getId()); this.validateEnv(); AccountDto accountDto = accountService.update(newAccountDto); GenericAccountResponse genericAccountResponse = new GenericAccountResponse(accountDto); return genericAccountResponse; }  }
AccountController { @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 }) public GenericAccountResponse updateAccount(@RequestBody @Valid AccountDto newAccountDto) { this.validateAuthenticatedUser(newAccountDto.getId()); this.validateEnv(); AccountDto accountDto = accountService.update(newAccountDto); GenericAccountResponse genericAccountResponse = new GenericAccountResponse(accountDto); return genericAccountResponse; }  @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 { @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 }) public GenericAccountResponse updateAccount(@RequestBody @Valid AccountDto newAccountDto) { this.validateAuthenticatedUser(newAccountDto.getId()); this.validateEnv(); AccountDto accountDto = accountService.update(newAccountDto); GenericAccountResponse genericAccountResponse = new GenericAccountResponse(accountDto); return genericAccountResponse; }  @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);  }