|
15 | 15 | import org.springframework.data.mongodb.core.query.Update; |
16 | 16 | import org.springframework.data.mongodb.core.query.UpdateDefinition; |
17 | 17 | import uk.nhs.adaptors.gp2gp.common.service.TimestampService; |
| 18 | +import uk.nhs.adaptors.gp2gp.ehr.exception.EhrExtractException; |
18 | 19 | import uk.nhs.adaptors.gp2gp.ehr.model.EhrExtractStatus; |
19 | 20 | import uk.nhs.adaptors.gp2gp.mhs.exception.UnrecognisedInteractionIdException; |
20 | 21 |
|
|
26 | 27 | import java.util.Optional; |
27 | 28 | import java.util.UUID; |
28 | 29 |
|
| 30 | +import static java.lang.String.format; |
29 | 31 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
30 | 32 | import static org.junit.jupiter.api.Assertions.assertEquals; |
31 | 33 | import static org.junit.jupiter.api.Assertions.assertFalse; |
@@ -307,6 +309,31 @@ void doesNotUpdateEhrExtractStatusWhenEhrContinueIsPresent() { |
307 | 309 | assertFalse(ehrExtractStatusResult.isPresent()); |
308 | 310 | } |
309 | 311 |
|
| 312 | + @Test |
| 313 | + void throwsEhrExtractExceptionWhenEhrExtractStatusIsNotFound() { |
| 314 | + EhrExtractStatusService ehrExtractStatusServiceSpy = spy(ehrExtractStatusService); |
| 315 | + String conversationId = generateRandomUppercaseUUID(); |
| 316 | + |
| 317 | + Optional<EhrExtractStatus> ehrExtractStatus = Optional.of(EhrExtractStatus.builder() |
| 318 | + .ehrExtractCorePending( |
| 319 | + EhrExtractStatus |
| 320 | + .EhrExtractCorePending |
| 321 | + .builder() |
| 322 | + .sentAt(Instant.now()) |
| 323 | + .taskId("22222").build()) |
| 324 | + .build()); |
| 325 | + doReturn(ehrExtractStatus).when(ehrExtractStatusRepository).findByConversationId(conversationId); |
| 326 | + |
| 327 | + doReturn(null).when(mongoTemplate).findAndModify(any(Query.class), any(UpdateDefinition.class), |
| 328 | + any(FindAndModifyOptions.class), any()); |
| 329 | + |
| 330 | + Exception exception = assertThrows(EhrExtractException.class, |
| 331 | + () -> ehrExtractStatusServiceSpy.updateEhrExtractStatusContinue(conversationId)); |
| 332 | + |
| 333 | + assertTrue(exception.getMessage() |
| 334 | + .contains(format("Received a Continue message with a conversationId %s that is not recognised", conversationId))); |
| 335 | + } |
| 336 | + |
310 | 337 | @Test |
311 | 338 | void expectTrueWhenEhrExtractStatusWithEhrReceivedAckWithErrorsAndExceededTimeoutLimit() { |
312 | 339 |
|
|
0 commit comments