Skip to content

Commit e7d0e7b

Browse files
stephenokeefeItneet
authored andcommitted
Add not found tests
1 parent b2bd3ab commit e7d0e7b

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerDownloadTranscriptIntTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import static uk.gov.hmcts.darts.audit.api.AuditActivity.DOWNLOAD_TRANSCRIPTION;
5555
import static uk.gov.hmcts.darts.common.enums.ExternalLocationTypeEnum.UNSTRUCTURED;
5656
import static uk.gov.hmcts.darts.common.enums.ObjectRecordStatusEnum.STORED;
57+
import static uk.gov.hmcts.darts.test.common.TestUtils.getContentsFromFile;
5758
import static uk.gov.hmcts.darts.transcriptions.enums.TranscriptionStatusEnum.APPROVED;
5859
import static uk.gov.hmcts.darts.transcriptions.enums.TranscriptionStatusEnum.COMPLETE;
5960
import static uk.gov.hmcts.darts.transcriptions.enums.TranscriptionStatusEnum.WITH_TRANSCRIBER;
@@ -320,7 +321,7 @@ void downloadTranscript_ShouldReturnOk_WithMicrosoftWordOld() throws Exception {
320321
}
321322

322323
@Test
323-
void downloadTranscript_ShouldReturnError_WhenNegativeTranscriptionIdUsed() throws Exception {
324+
void downloadTranscript_ShouldReturnBadRequest_WhenNegativeTranscriptionIdUsed() throws Exception {
324325
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/transcriptions/-123/document")
325326
.header(
326327
"accept",
@@ -333,9 +334,7 @@ void downloadTranscript_ShouldReturnError_WhenNegativeTranscriptionIdUsed() thro
333334

334335
String actualResponse = mvcResult.getResponse().getContentAsString();
335336

336-
String expectedResponse = """
337-
{"type":"TRANSCRIPTION_124","title":"Invalid transcription id","status":400}
338-
""";
337+
String expectedResponse = getContentsFromFile("tests/transcriptions/transcription/expectedResponseBadRequest.json");
339338
JSONAssert.assertEquals(expectedResponse, actualResponse, JSONCompareMode.NON_EXTENSIBLE);
340339

341340
verifyNoInteractions(mockAuditApi);

src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,31 @@ void getTranscription_ShouldReturnBadRequest_WhenNegativeTranscriptionId() throw
295295
JSONAssert.assertEquals(expectedResponse, actualResponse, JSONCompareMode.NON_EXTENSIBLE);
296296
}
297297

298+
@Test
299+
void getTranscription_ShouldReturnNotFound_WhenTranscriptDoesNotExist() throws Exception {
300+
TranscriptionEntity transcriptionEntity = transactionalUtil.executeInTransaction(() -> {
301+
HearingEntity hearingEntity = dartsDatabase.getHearingRepository().findAll().getFirst();
302+
TranscriptionEntity transcription = dartsDatabase.getTranscriptionStub().createTranscription(hearingEntity);
303+
transcription.setStartTime(SOME_DATE_TIME);
304+
transcription.setEndTime(SOME_DATE_TIME);
305+
transcription = dartsDatabase.save(transcription);
306+
UserAccountEntity userAccount = dartsDatabase.getUserAccountRepository().findById(transcription.getCreatedById()).orElseThrow();
307+
308+
addTranscriptionWorkflow(transcription, userAccount, "comment1", TranscriptionStatusEnum.REQUESTED);
309+
addTranscriptionWorkflow(transcription, userAccount, "comment2", TranscriptionStatusEnum.APPROVED);
310+
transcription.getCourtroom().getCourthouse().getCourthouseName();
311+
transcription.getRequestedBy().getUserName();
312+
return transcription;
313+
});
314+
dartsDatabase.updateCreatedBy(transcriptionEntity, OffsetDateTime.of(2023, 6, 20, 10, 0, 0, 0, ZoneOffset.UTC));
315+
316+
MockHttpServletRequestBuilder requestBuilder = get(ENDPOINT_URL_TRANSCRIPTION, transcriptionEntity.getId() + 1);
317+
MvcResult response = mockMvc.perform(requestBuilder).andExpect(status().isNotFound()).andReturn();
318+
String actualResponse = response.getResponse().getContentAsString();
319+
String expectedResponse = getContentsFromFile("tests/transcriptions/transcription/expectedResponseNotFound.json");
320+
JSONAssert.assertEquals(expectedResponse, actualResponse, JSONCompareMode.NON_EXTENSIBLE);
321+
}
322+
298323
private void addCommentToWorkflow(TranscriptionWorkflowEntity workflowEntity, String comment, UserAccountEntity userAccount) {
299324
addComment(workflowEntity.getTranscription(), workflowEntity, comment, userAccount);
300325
}

src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionWithTranscriberIntTest.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
3737
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
3838
import static uk.gov.hmcts.darts.audit.api.AuditActivity.ACCEPT_TRANSCRIPTION;
39+
import static uk.gov.hmcts.darts.test.common.TestUtils.getContentsFromFile;
3940
import static uk.gov.hmcts.darts.transcriptions.enums.TranscriptionStatusEnum.APPROVED;
4041
import static uk.gov.hmcts.darts.transcriptions.enums.TranscriptionStatusEnum.COMPLETE;
4142
import static uk.gov.hmcts.darts.transcriptions.enums.TranscriptionStatusEnum.WITH_TRANSCRIBER;
@@ -133,7 +134,7 @@ void updateTranscriptionWithTranscriberWithoutComment() throws Exception {
133134
}
134135

135136
@Test
136-
void updateTranscriptionShouldReturnTranscriptionNotFoundError() throws Exception {
137+
void updateTranscription_ShouldReturnBadRequest_WhenInvalidTranscriptionId() throws Exception {
137138
UpdateTranscriptionRequest updateTranscription = new UpdateTranscriptionRequest();
138139
updateTranscription.setTranscriptionStatusId(WITH_TRANSCRIBER.getId());
139140

@@ -146,9 +147,28 @@ void updateTranscriptionShouldReturnTranscriptionNotFoundError() throws Exceptio
146147
.andReturn();
147148

148149
String actualJson = mvcResult.getResponse().getContentAsString();
149-
String expectedJson = """
150-
{"type":"TRANSCRIPTION_124","title":"Invalid transcription id","status":400}
151-
""";
150+
String expectedJson = getContentsFromFile("tests/transcriptions/transcription/expectedResponseBadRequest.json");
151+
JSONAssert.assertEquals(expectedJson, actualJson, JSONCompareMode.NON_EXTENSIBLE);
152+
153+
verifyNoInteractions(mockAuditApi);
154+
}
155+
156+
@Test
157+
void updateTranscription_ShouldReturnNotFound_WhenTranscriptionDoesNotExist() throws Exception {
158+
UpdateTranscriptionRequest updateTranscription = new UpdateTranscriptionRequest();
159+
updateTranscription.setTranscriptionStatusId(WITH_TRANSCRIBER.getId());
160+
161+
MockHttpServletRequestBuilder requestBuilder = patch(URI.create(
162+
String.format("/transcriptions/%d", transcriptionId + 1)))
163+
.header("Content-Type", "application/json")
164+
.content(objectMapper.writeValueAsString(updateTranscription));
165+
MvcResult mvcResult = mockMvc.perform(requestBuilder)
166+
.andExpect(status().isNotFound())
167+
.andReturn();
168+
169+
String actualJson = mvcResult.getResponse().getContentAsString();
170+
String expectedJson = getContentsFromFile("tests/transcriptions/transcription/expectedResponseNotFound.json");
171+
152172
JSONAssert.assertEquals(expectedJson, actualJson, JSONCompareMode.NON_EXTENSIBLE);
153173

154174
verifyNoInteractions(mockAuditApi);

0 commit comments

Comments
 (0)