Skip to content

Commit

Permalink
finish IT for unit controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Jan 23, 2025
1 parent 69e7b18 commit 587bf15
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public UnitDto updateUnit(@Parameter(description = "The ID for updating a Team."
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Deleted Action by Id"),
@ApiResponse(responseCode = "404", description = "Did not find the Action with requested id") })
@DeleteMapping("/{unitId}")
public Unit deleteUnitById(@PathVariable long unitId) {
return unitAuthorizationService.deleteUnitById(unitId);
public void deleteUnitById(@PathVariable long unitId) {
unitAuthorizationService.deleteUnitById(unitId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ public Unit updateUnit(Long unitId, Unit unit) {
return unitBusinessService.updateEntity(unitId, unit);
}

public Unit deleteUnitById(Long unitId) {
public void deleteUnitById(Long unitId) {
AuthorizationUser authorizationUser = authorizationService.updateOrAddAuthorizationUser();
Unit unit = unitBusinessService.getEntityById(unitId);
validateOwner(unit, authorizationUser);
unitBusinessService.deleteEntityById(unitId);
return unit;
}

private void validateOwner(Unit unit, AuthorizationUser authorizationUser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void shouldReturn403ForWrongUserWhenUpdatingUnit() throws Exception {

@Test
void shouldReturn403ForWrongUserWhenDeletingUnit() throws Exception {
when(unitAuthorizationService.deleteUnitById(any())).thenThrow(new ResponseStatusException(HttpStatus.FORBIDDEN));
doThrow(new ResponseStatusException(HttpStatus.FORBIDDEN)).when(unitAuthorizationService).deleteUnitById(101L);
mvc
.perform(delete(URL_BASE + "/101")
.with(SecurityMockMvcRequestPostProcessors.csrf())
Expand Down

0 comments on commit 587bf15

Please sign in to comment.