Skip to content

Commit

Permalink
[HOCS-6767] Add endpoint to delete case by reference (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-horton-ho-sas authored Aug 16, 2023
1 parent 910fdbf commit a244d22
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import uk.gov.digital.ho.hocs.casework.security.AllocationLevel;
import uk.gov.digital.ho.hocs.casework.security.Authorised;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
Expand Down Expand Up @@ -96,6 +95,16 @@ public ResponseEntity<Void> deleteCase(@PathVariable UUID caseUUID, @PathVariabl
return ResponseEntity.ok().build();
}

@Authorised(accessLevel = AccessLevel.CASE_ADMIN)
@DeleteMapping(value = "/case/ref/{reference}/{deleted}")
public ResponseEntity<Void> deleteCaseByReference(@PathVariable String reference, @PathVariable Boolean deleted)
{
String decodedRef = URLDecoder.decode(reference, StandardCharsets.UTF_8);
CaseData caseData = caseDataService.getCaseDataByReference(decodedRef);
caseDataService.deleteCase(caseData.getUuid(), deleted);
return ResponseEntity.ok().build();
}

@Authorised(accessLevel = AccessLevel.READ)
@GetMapping(value = "/case/{caseUUID}/timeline")
public ResponseEntity<Set<TimelineItemDto>> getCaseTimeline(@PathVariable UUID caseUUID) {
Expand Down Expand Up @@ -257,9 +266,8 @@ public ResponseEntity<Void> mapCaseDataValues(@PathVariable UUID caseUUID,
}

@GetMapping(value = "/case/data/{reference}")
public ResponseEntity<GetCaseResponse> getCaseDataByReference(
@PathVariable String reference) throws UnsupportedEncodingException {
String decodedRef = URLDecoder.decode(reference, StandardCharsets.UTF_8.name());
public ResponseEntity<GetCaseResponse> getCaseDataByReference(@PathVariable String reference) {
String decodedRef = URLDecoder.decode(reference, StandardCharsets.UTF_8);
CaseData caseData = caseDataService.getCaseDataByReference(decodedRef);
return ResponseEntity.ok(GetCaseResponse.from(caseData, true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import uk.gov.digital.ho.hocs.casework.api.dto.CaseDataType;
Expand Down Expand Up @@ -70,6 +69,8 @@ public class CaseDataResourceTest {

private final UUID uuid = UUID.randomUUID();

private static final String CASE_REFERENCE = "WCS/87654321/23";

@Mock
private CaseDataService caseDataService;

Expand Down Expand Up @@ -173,6 +174,23 @@ public void shouldDeleteCase() {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}

@Test
public void shouldDeleteCaseByReference() {

doNothing().when(caseDataService).deleteCase(uuid, true);
when(caseDataService.getCaseDataByReference(CASE_REFERENCE)).thenReturn(buildStubCaseData(uuid));

ResponseEntity<Void> response = caseDataResource.deleteCaseByReference(CASE_REFERENCE, true);

verify(caseDataService, times(1)).getCaseDataByReference(CASE_REFERENCE);
verify(caseDataService, times(1)).deleteCase(uuid, true);

verifyNoMoreInteractions(caseDataService);

assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}

@Test
public void shouldGetCaseSummary() {

Expand Down Expand Up @@ -439,4 +457,8 @@ public void testShouldReturnOkWhenMapCaseDataValuesCalled() {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}

private CaseData buildStubCaseData(UUID uuid) {
return new CaseData(null, uuid, null, null, null, false, null, null, null, null, null, null, null, null, false, null, null, null);
}

}

0 comments on commit a244d22

Please sign in to comment.