@Test public void testUpdateShift() { this.createTwoShiftsAndVerify(); GenericShiftResponse genericShiftResponse = companyClient.updateShift(AuthConstant.AUTHORIZATION_SUPPORT_USER, shiftDto1); assertThat(genericShiftResponse.isSuccess()).isTrue(); assertThat(genericShiftResponse.getShift()).isEqualTo(shiftDto1); when(botClient.alertRemovedShift(any(AlertRemovedShiftRequest.class))) .thenReturn(BaseResponse.builder().message("Removed Shift Alerted").build()); ShiftDto shiftDto1Clone1 = shiftDto1.toBuilder().build(); shiftDto1Clone1.setPublished(false); genericShiftResponse = companyClient.updateShift(AuthConstant.AUTHORIZATION_SUPPORT_USER, shiftDto1Clone1); assertThat(genericShiftResponse.isSuccess()).isTrue(); assertThat(genericShiftResponse.getShift()).isEqualTo(shiftDto1Clone1); ArgumentCaptor<AlertRemovedShiftRequest> argument1 = ArgumentCaptor.forClass(AlertRemovedShiftRequest.class); verify(botClient, times(1)).alertRemovedShift(argument1.capture()); AlertRemovedShiftRequest alertRemovedShiftRequest = argument1.getValue(); assertThat(alertRemovedShiftRequest.getUserId()).isEqualTo(directoryEntryDto1.getUserId()); assertThat(alertRemovedShiftRequest.getOldShift()).isEqualTo(shiftDto1); ShiftDto shiftDto1Clone2 = shiftDto1Clone1.toBuilder().build(); shiftDto1Clone2.setStop(Instant.now().plus(10, ChronoUnit.DAYS)); genericShiftResponse = companyClient.updateShift(AuthConstant.AUTHORIZATION_SUPPORT_USER, shiftDto1Clone2); assertThat(genericShiftResponse.isSuccess()).isTrue(); assertThat(genericShiftResponse.getShift()).isEqualTo(shiftDto1Clone2); ShiftDto shiftDto1Clone3 = shiftDto1Clone2.toBuilder().build(); shiftDto1Clone3.setPublished(true); genericShiftResponse = companyClient.updateShift(AuthConstant.AUTHORIZATION_SUPPORT_USER, shiftDto1Clone3); assertThat(genericShiftResponse.isSuccess()).isTrue(); assertThat(genericShiftResponse.getShift()).isEqualTo(shiftDto1Clone3); ArgumentCaptor<AlertNewShiftRequest> argument2 = ArgumentCaptor.forClass(AlertNewShiftRequest.class); verify(botClient, times(3)).alertNewShift(argument2.capture()); AlertNewShiftRequest alertNewShiftRequest = argument2.getAllValues().get(2); assertThat(alertNewShiftRequest.getUserId()).isEqualTo(shiftDto1Clone3.getUserId()); assertThat(alertNewShiftRequest.getNewShift()).isEqualTo(shiftDto1Clone3); when(botClient.alertChangedShift(any(AlertChangedShiftRequest.class))) .thenReturn(BaseResponse.builder().message("Changed Shift Alerted").build()); ShiftDto shiftDto1Clone4 = shiftDto1Clone3.toBuilder().build(); shiftDto1Clone4.setStop(Instant.now().plus(8, ChronoUnit.DAYS)); genericShiftResponse = companyClient.updateShift(AuthConstant.AUTHORIZATION_SUPPORT_USER, shiftDto1Clone4); assertThat(genericShiftResponse.isSuccess()).isTrue(); assertThat(genericShiftResponse.getShift()).isEqualTo(shiftDto1Clone4); ArgumentCaptor<AlertChangedShiftRequest> argument3 = ArgumentCaptor.forClass(AlertChangedShiftRequest.class); verify(botClient, times(1)).alertChangedShift(argument3.capture()); AlertChangedShiftRequest alertChangedShiftRequest = argument3.getValue(); assertThat(alertChangedShiftRequest.getUserId()).isEqualTo(directoryEntryDto1.getUserId()); assertThat(alertChangedShiftRequest.getOldShift()).isEqualTo(shiftDto1Clone3); assertThat(alertChangedShiftRequest.getNewShift()).isEqualTo(shiftDto1Clone4); ShiftDto shiftDto1Clone5 = shiftDto1Clone4.toBuilder().build(); String userId3 = UUID.randomUUID().toString(); shiftDto1Clone5.setUserId(userId3); when(directoryService.getDirectoryEntry(company.getId(), userId3)).thenReturn(null); genericShiftResponse = companyClient.updateShift(AuthConstant.AUTHORIZATION_SUPPORT_USER, shiftDto1Clone5); assertThat(genericShiftResponse.isSuccess()).isTrue(); assertThat(genericShiftResponse.getShift()).isEqualTo(shiftDto1Clone5); ArgumentCaptor<AlertNewShiftRequest> argument4 = ArgumentCaptor.forClass(AlertNewShiftRequest.class); verify(botClient, times(4)).alertNewShift(argument4.capture()); AlertNewShiftRequest alertNewShiftRequest2 = argument4.getAllValues().get(3); assertThat(alertNewShiftRequest2.getUserId()).isEqualTo(shiftDto1Clone5.getUserId()); assertThat(alertNewShiftRequest2.getNewShift()).isEqualTo(shiftDto1Clone5); ArgumentCaptor<AlertRemovedShiftRequest> argument5 = ArgumentCaptor.forClass(AlertRemovedShiftRequest.class); verify(botClient, times(2)).alertRemovedShift(argument5.capture()); AlertRemovedShiftRequest alertRemovedShiftRequest2 = argument5.getAllValues().get(1); assertThat(alertRemovedShiftRequest2.getUserId()).isEqualTo(shiftDto1Clone4.getUserId()); assertThat(alertRemovedShiftRequest2.getOldShift()).isEqualTo(shiftDto1Clone4); }
@PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftResponse updateShift(@RequestBody @Validated ShiftDto shiftDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(shiftDto.getCompanyId()); } ShiftDto updatedShiftDto = shiftService.updateShift(shiftDto); return new GenericShiftResponse(updatedShiftDto); }
ShiftController { @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftResponse updateShift(@RequestBody @Validated ShiftDto shiftDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(shiftDto.getCompanyId()); } ShiftDto updatedShiftDto = shiftService.updateShift(shiftDto); return new GenericShiftResponse(updatedShiftDto); } }
ShiftController { @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftResponse updateShift(@RequestBody @Validated ShiftDto shiftDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(shiftDto.getCompanyId()); } ShiftDto updatedShiftDto = shiftService.updateShift(shiftDto); return new GenericShiftResponse(updatedShiftDto); }  }
ShiftController { @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftResponse updateShift(@RequestBody @Validated ShiftDto shiftDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(shiftDto.getCompanyId()); } ShiftDto updatedShiftDto = shiftService.updateShift(shiftDto); return new GenericShiftResponse(updatedShiftDto); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse createShift(@RequestBody @Validated CreateShiftRequest request); @PostMapping(path = "/list_worker_shifts") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_BOT_SERVICE, AuthConstant.AUTHORIZATION_ICAL_SERVICE }) GenericShiftListResponse listWorkerShifts(@RequestBody @Validated WorkerShiftListRequest request); @PostMapping(path = "/list_shifts") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftListResponse listShifts(@RequestBody @Validated ShiftListRequest request); @PostMapping(path = "/bulk_publish") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftListResponse bulkPublishShifts(@RequestBody @Validated BulkPublishShiftsRequest request); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse getShift(@RequestParam String shiftId, @RequestParam String teamId, @RequestParam  String companyId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse updateShift(@RequestBody @Validated ShiftDto shiftDto); @DeleteMapping(path = "/delete") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse deleteShift(@RequestParam String shiftId, @RequestParam String teamId, @RequestParam String companyId); }
ShiftController { @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericShiftResponse updateShift(@RequestBody @Validated ShiftDto shiftDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(shiftDto.getCompanyId()); } ShiftDto updatedShiftDto = shiftService.updateShift(shiftDto); return new GenericShiftResponse(updatedShiftDto); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse createShift(@RequestBody @Validated CreateShiftRequest request); @PostMapping(path = "/list_worker_shifts") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_BOT_SERVICE, AuthConstant.AUTHORIZATION_ICAL_SERVICE }) GenericShiftListResponse listWorkerShifts(@RequestBody @Validated WorkerShiftListRequest request); @PostMapping(path = "/list_shifts") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftListResponse listShifts(@RequestBody @Validated ShiftListRequest request); @PostMapping(path = "/bulk_publish") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftListResponse bulkPublishShifts(@RequestBody @Validated BulkPublishShiftsRequest request); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse getShift(@RequestParam String shiftId, @RequestParam String teamId, @RequestParam  String companyId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericShiftResponse updateShift(@RequestBody @Validated ShiftDto shiftDto); @DeleteMapping(path = "/delete") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) BaseResponse deleteShift(@RequestParam String shiftId, @RequestParam String teamId, @RequestParam String companyId);  }