Skip to content

Commit b8e0173

Browse files
committed
marking EhrExtractStatus as failed in a test scenario
1 parent 24da3bb commit b8e0173

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

service/src/intTest/java/uk/nhs/adaptors/gp2gp/ehr/EhrResendControllerTest.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,47 @@
1313
import uk.nhs.adaptors.gp2gp.testcontainers.ActiveMQExtension;
1414
import uk.nhs.adaptors.gp2gp.testcontainers.MongoDBExtension;
1515

16+
import java.time.Duration;
17+
import java.time.Instant;
18+
import java.util.List;
19+
import java.util.UUID;
20+
1621
import static org.assertj.core.api.Assertions.assertThat;
22+
import static uk.nhs.adaptors.gp2gp.ehr.EhrStatusConstants.INCUMBENT_NACK_CODE;
23+
import static uk.nhs.adaptors.gp2gp.ehr.EhrStatusConstants.INCUMBENT_NACK_DISPLAY;
24+
1725

1826
@SpringBootTest
1927
@DirtiesContext
2028
@ExtendWith({SpringExtension.class, MongoDBExtension.class, ActiveMQExtension.class, MockitoExtension.class})
2129
public class EhrResendControllerTest {
30+
31+
public static final Instant NOW = Instant.parse("2024-01-01T10:00:00Z");
32+
private static final Instant FIVE_DAYS_AGO = NOW.minus(Duration.ofDays(5));
33+
2234
@Autowired
2335
private EhrExtractStatusRepository ehrExtractStatusRepository;
2436
@Autowired
2537
private EhrResendController ehrResendController;
2638

2739
@Test
2840
public void When_AnEhrExtractHasFailed_Expect_RespondsWith202() {
41+
42+
String ehrMessageRef = generateRandomUppercaseUUID();
2943
var ehrExtractStatus = new EhrExtractStatus();
3044
ehrExtractStatus.setConversationId("123-456");
31-
// TODO: Mark ehrExtractStatus as failed.
45+
ehrExtractStatus.setEhrReceivedAcknowledgement(EhrExtractStatus.EhrReceivedAcknowledgement.builder()
46+
.conversationClosed(FIVE_DAYS_AGO)
47+
.errors(List.of(
48+
EhrExtractStatus.EhrReceivedAcknowledgement.ErrorDetails.builder()
49+
.code(INCUMBENT_NACK_CODE)
50+
.display(INCUMBENT_NACK_DISPLAY)
51+
.build()))
52+
.messageRef(ehrMessageRef)
53+
.received(FIVE_DAYS_AGO)
54+
.rootId(generateRandomUppercaseUUID())
55+
.build());
56+
3257
ehrExtractStatusRepository.save(ehrExtractStatus);
3358

3459
var response = ehrResendController.scheduleEhrExtractResend("123-456");
@@ -45,4 +70,10 @@ public void When_AnEhrExtractDoesNotExist_Expect_RespondsWith404() {
4570
// TODO: Add more detail to OperationOutcome
4671
assertThat(response.getBody()).usingRecursiveComparison().isEqualTo(new OperationOutcome());
4772
}
73+
74+
private String generateRandomUppercaseUUID() {
75+
return UUID.randomUUID().toString().toUpperCase();
76+
}
77+
78+
4879
}

0 commit comments

Comments
 (0)