@Test public void testCreateDirectory() { String companyId = UUID.randomUUID().toString(); String interalId = UUID.randomUUID().toString(); when(companyRepo.existsById(companyId)).thenReturn(true); String name = "testAccount"; String email = "test001@staffjoy.xyz"; String phoneNumber = "18001981226"; Instant memberSince = Instant.now().minusSeconds(24 * 3600 * 30); String photoUrl = "https: AccountDto accountDto = AccountDto.builder() .id(UUID.randomUUID().toString()) .name(name) .email(email) .phoneNumber(phoneNumber) .memberSince(memberSince) .photoUrl(photoUrl) .build(); GenericAccountResponse genericAccountResponse = new GenericAccountResponse(accountDto); when(accountClient.getOrCreateAccount(anyString(), any(GetOrCreateRequest.class))) .thenReturn(genericAccountResponse); when(botClient.onboardWorker(any(OnboardWorkerRequest.class))).thenReturn(BaseResponse.builder().message("worker onboard").build()); when(accountClient.trackEvent(any(TrackEventRequest.class))).thenReturn(BaseResponse.builder().build()); NewDirectoryEntry newDirectoryEntry = NewDirectoryEntry.builder() .internalId(interalId) .companyId(companyId) .name(name) .email(email) .phoneNumber(phoneNumber) .build(); GenericDirectoryResponse genericDirectoryResponse = companyClient.createDirectory(AuthConstant.AUTHORIZATION_WWW_SERVICE, newDirectoryEntry); log.info(genericDirectoryResponse.toString()); assertThat(genericDirectoryResponse.isSuccess()).isTrue(); DirectoryEntryDto directoryEntryDto = genericDirectoryResponse.getDirectoryEntry(); assertThat(directoryEntryDto.getUserId()).isEqualTo(accountDto.getId()); assertThat(directoryEntryDto.getName()).isEqualTo(name); assertThat(directoryEntryDto.getEmail()).isEqualTo(email); assertThat(directoryEntryDto.getPhoneNumber()).isEqualTo(phoneNumber); assertThat(directoryEntryDto.getCompanyId()).isEqualTo(companyId); assertThat(directoryEntryDto.getInternalId()).isEqualTo(interalId); assertThat(directoryEntryDto.getPhotoUrl()).isEqualTo(photoUrl); ArgumentCaptor<TrackEventRequest> argument1 = ArgumentCaptor.forClass(TrackEventRequest.class); verify(accountClient, times(1)).trackEvent(argument1.capture()); TrackEventRequest trackEventRequest = argument1.getValue(); assertThat(trackEventRequest.getUserId()).isEqualTo(TestConfig.TEST_USER_ID); assertThat(trackEventRequest.getEvent()).isEqualTo("directoryentry_created"); ArgumentCaptor<OnboardWorkerRequest> argument2 = ArgumentCaptor.forClass(OnboardWorkerRequest.class); verify(botClient, times(1)).onboardWorker(argument2.capture()); OnboardWorkerRequest onboardWorkerRequest = argument2.getValue(); assertThat(onboardWorkerRequest.getCompanyId()).isEqualTo(companyId); assertThat(onboardWorkerRequest.getUserId()).isEqualTo(accountDto.getId()); genericDirectoryResponse = companyClient.createDirectory(AuthConstant.AUTHORIZATION_WWW_SERVICE, newDirectoryEntry); log.info(genericDirectoryResponse.toString()); assertThat(genericDirectoryResponse.isSuccess()).isFalse(); assertThat(genericDirectoryResponse.getCode()).isEqualTo(ResultCode.FAILURE); }
@PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); }
DirectoryController { @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); } }
DirectoryController { @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); }  }
DirectoryController { @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request); @GetMapping(path = "/list") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) ListDirectoryResponse listDirectories(@RequestParam String companyId,
                                                 @RequestParam(defaultValue = "0") int offset,
                                                 @RequestParam(defaultValue = "0") int limit); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericDirectoryResponse getDirectoryEntry(@RequestParam String companyId, @RequestParam String userId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericDirectoryResponse updateDirectoryEntry(@RequestBody @Validated DirectoryEntryDto request); @GetMapping(path = "/get_associations") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GetAssociationResponse getAssociations(@RequestParam String companyId,
                                                  @RequestParam(defaultValue = "0") int offset,
                                                  @RequestParam(defaultValue = "0") int limit); }
DirectoryController { @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request); @GetMapping(path = "/list") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) ListDirectoryResponse listDirectories(@RequestParam String companyId,
                                                 @RequestParam(defaultValue = "0") int offset,
                                                 @RequestParam(defaultValue = "0") int limit); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericDirectoryResponse getDirectoryEntry(@RequestParam String companyId, @RequestParam String userId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericDirectoryResponse updateDirectoryEntry(@RequestBody @Validated DirectoryEntryDto request); @GetMapping(path = "/get_associations") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GetAssociationResponse getAssociations(@RequestParam String companyId,
                                                  @RequestParam(defaultValue = "0") int offset,
                                                  @RequestParam(defaultValue = "0") int limit);  }