|
| 1 | +package uk.nhs.adaptors.gp2gp.ehr; |
| 2 | + |
| 3 | +import org.hl7.fhir.dstu3.model.OperationOutcome; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 6 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import org.springframework.boot.test.context.SpringBootTest; |
| 9 | +import org.springframework.http.HttpStatus; |
| 10 | +import org.springframework.test.annotation.DirtiesContext; |
| 11 | +import org.springframework.test.context.junit.jupiter.SpringExtension; |
| 12 | +import uk.nhs.adaptors.gp2gp.ehr.model.EhrExtractStatus; |
| 13 | +import uk.nhs.adaptors.gp2gp.testcontainers.ActiveMQExtension; |
| 14 | +import uk.nhs.adaptors.gp2gp.testcontainers.MongoDBExtension; |
| 15 | + |
| 16 | +import static org.assertj.core.api.Assertions.assertThat; |
| 17 | + |
| 18 | +@SpringBootTest |
| 19 | +@DirtiesContext |
| 20 | +@ExtendWith({SpringExtension.class, MongoDBExtension.class, ActiveMQExtension.class, MockitoExtension.class}) |
| 21 | +public class EhrResendControllerTest { |
| 22 | + @Autowired |
| 23 | + private EhrExtractStatusRepository ehrExtractStatusRepository; |
| 24 | + @Autowired |
| 25 | + private EhrResendController ehrResendController; |
| 26 | + |
| 27 | + @Test |
| 28 | + public void When_AnEhrExtractHasFailed_Expect_RespondsWith202() { |
| 29 | + var ehrExtractStatus = new EhrExtractStatus(); |
| 30 | + ehrExtractStatus.setConversationId("123-456"); |
| 31 | + // TODO: Mark ehrExtractStatus as failed. |
| 32 | + ehrExtractStatusRepository.save(ehrExtractStatus); |
| 33 | + |
| 34 | + var response = ehrResendController.scheduleEhrExtractResend("123-456"); |
| 35 | + |
| 36 | + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED); |
| 37 | + assertThat(response.getBody()).isNull(); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void When_AnEhrExtractDoesNotExist_Expect_RespondsWith404() { |
| 42 | + var response = ehrResendController.scheduleEhrExtractResend("123-456"); |
| 43 | + |
| 44 | + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); |
| 45 | + // TODO: Add more detail to OperationOutcome |
| 46 | + assertThat(response.getBody()).usingRecursiveComparison().isEqualTo(new OperationOutcome()); |
| 47 | + } |
| 48 | +} |
0 commit comments