Skip to content

Commit

Permalink
DMP-3375 Implement admin endpoint to get case details by id
Browse files Browse the repository at this point in the history
Added admin endpoint to get case details
  • Loading branch information
karen-hedges committed Feb 24, 2025
1 parent aad3d24 commit 58f7ffd
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class CaseControllerAdminGetCaseByIdIntTest extends IntegrationBase {
private static final String SOME_COURTHOUSE = "SOME-COURTHOUSE";
private static final String SOME_COURTROOM = "some-courtroom";
private static final String SOME_CASE_NUMBER = "1";
public static final OffsetDateTime DATE_TIME = OffsetDateTime.parse("2023-06-26T13:00:00Z");

@Autowired
private transient MockMvc mockMvc;
Expand Down Expand Up @@ -102,7 +103,7 @@ void adminGetCaseById_ShouldReturnForbiddenError() throws Exception {
}

@Test
void adminGetCaseById_Success() throws Exception {
void adminGetCaseById_WithCaseOpenAndReportingRestrictions() throws Exception {
// given
superAdminUserStub.givenUserIsAuthorised(mockUserIdentity);

Expand All @@ -114,7 +115,7 @@ void adminGetCaseById_Success() throws Exception {
);

List<OffsetDateTime> eventDateTimes = new ArrayList<>();
eventDateTimes.add(OffsetDateTime.parse("2023-06-26T13:00:00Z"));
eventDateTimes.add(DATE_TIME);
var reportingRestrictions = createEventsWithDifferentTimestamps(eventDateTimes).stream()
.map(eve -> dartsDatabase.addHandlerToEvent(eve, 54))
.toList();
Expand All @@ -134,7 +135,49 @@ void adminGetCaseById_Success() throws Exception {
// then
String actualResponse = mvcResult.getResponse().getContentAsString();
String expectedResponse = getContentsFromFile(
"tests/cases/CaseControllerAdminGetCaseByIdTest/testOk/expectedResponse.json");
"tests/cases/CaseControllerAdminGetCaseByIdTest/testCaseOpen/expectedResponse.json");
expectedResponse = expectedResponse.replace("<CREATED_AT>", courtCase.getCreatedDateTime().toString());
expectedResponse = expectedResponse.replace("<LAST_MODIFIED_AT>", courtCase.getLastModifiedDateTime().toString());
JSONAssert.assertEquals(expectedResponse, actualResponse, JSONCompareMode.NON_EXTENSIBLE);

}

@Test
void adminGetCaseById_WithCaseClosedAndReportingRestrictions() throws Exception {
// given
superAdminUserStub.givenUserIsAuthorised(mockUserIdentity);

HearingEntity hearingEntity = dartsDatabase.givenTheDatabaseContainsCourtCaseWithHearingAndCourthouseWithRoom(
"123",
SOME_COURTHOUSE,
SOME_COURTROOM,
DateConverterUtil.toLocalDateTime(SOME_DATE_TIME)
);

List<OffsetDateTime> eventDateTimes = new ArrayList<>();
eventDateTimes.add(DATE_TIME);
var reportingRestrictions = createEventsWithDifferentTimestamps(eventDateTimes).stream()
.map(eve -> dartsDatabase.addHandlerToEvent(eve, 54))
.toList();
hearingEntity = dartsDatabase.saveEventsForHearing(hearingEntity, reportingRestrictions);

CourtCaseEntity courtCase = hearingEntity.getCourtCase();
courtCase.addProsecutor(createProsecutorForCase(courtCase));
courtCase.addDefendant(createDefendantForCase(courtCase));
courtCase.addDefence("aDefence");
courtCase.setClosed(true);
courtCase.setCaseClosedTimestamp(DATE_TIME);
courtCase = dartsDatabase.save(courtCase);

MockHttpServletRequestBuilder requestBuilder = get(ENDPOINT_URL, courtCase.getId());

// when
MvcResult mvcResult = mockMvc.perform(requestBuilder).andExpect(status().isOk()).andReturn();

// then
String actualResponse = mvcResult.getResponse().getContentAsString();
String expectedResponse = getContentsFromFile(
"tests/cases/CaseControllerAdminGetCaseByIdTest/testCaseClosed/expectedResponse.json");
expectedResponse = expectedResponse.replace("<CREATED_AT>", courtCase.getCreatedDateTime().toString());
expectedResponse = expectedResponse.replace("<LAST_MODIFIED_AT>", courtCase.getLastModifiedDateTime().toString());
log.info("actualResponse: {}", actualResponse);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"id": 2,
"courthouse": {
"id": 2,
"display_name": "SOME-COURTHOUSE"
},
"case_number": "123",
"defendants": [
"some-defendant"
],
"judges": [
"123JUDGE1"
],
"prosecutors": [
"some-prosecutor"
],
"defenders": [
"aDefence"
],
"reporting_restrictions": [
{
"hearing_id": 4,
"event_id": 2,
"event_name": "Judge directed on reporting restrictions",
"event_text": "some-event-text-1",
"event_ts": "2023-06-26T13:00:00Z"
}
],
"case_closed_date_time": "2023-06-26T13:00:00Z",
"case_status": "CLOSED",
"created_at": "<CREATED_AT>",
"created_by": 0,
"last_modified_at": "<LAST_MODIFIED_AT>",
"last_modified_by": 0,
"is_deleted": false,
"is_data_anonymised": false,
"is_interpreter_used": false
}

0 comments on commit 58f7ffd

Please sign in to comment.