From 446f6d54a4f46ebc8f89eae62fbf310a8ea6752a Mon Sep 17 00:00:00 2001 From: Gabriel Dorsch Date: Mon, 30 Sep 2024 12:08:57 -0400 Subject: [PATCH 1/2] Updated submission history test cases --- .../SubmissionFunctionIntegrationTests.kt | 129 +++++++++++++++++- 1 file changed, 126 insertions(+), 3 deletions(-) diff --git a/prime-router/src/test/kotlin/history/azure/SubmissionFunctionIntegrationTests.kt b/prime-router/src/test/kotlin/history/azure/SubmissionFunctionIntegrationTests.kt index 4df2eccea16..34bd4b30719 100644 --- a/prime-router/src/test/kotlin/history/azure/SubmissionFunctionIntegrationTests.kt +++ b/prime-router/src/test/kotlin/history/azure/SubmissionFunctionIntegrationTests.kt @@ -71,6 +71,128 @@ class SubmissionFunctionIntegrationTests { @Test fun `it should return a history for partially delivered submission`() { + val submittedReport = reportGraph { + topic(Topic.FULL_ELR) + format(MimeFormat.HL7) + sender(UniversalPipelineTestUtils.hl7Sender) + + submission { + action(TaskAction.receive) + reportGraphNode { + action(TaskAction.convert) + log(ActionLog(InvalidParamMessage("log"), type = ActionLogLevel.warning)) + reportGraphNode { + action(TaskAction.destination_filter) + reportGraphNode { + action(TaskAction.none) + receiver(UniversalPipelineTestUtils.universalPipelineOrganization.receivers[1]) + itemCount(0) + } + } + reportGraphNode { + action(TaskAction.destination_filter) + reportGraphNode { + action(TaskAction.receiver_filter) + reportGraphNode { + action(TaskAction.translate) + receiver(UniversalPipelineTestUtils.universalPipelineOrganization.receivers[0]) + reportGraphNode { + action(TaskAction.send) + transportResult("Success") + receiver(UniversalPipelineTestUtils.universalPipelineOrganization.receivers[0]) + } + } + } + reportGraphNode { + action(TaskAction.receiver_filter) + reportGraphNode { + action(TaskAction.none) + receiver(UniversalPipelineTestUtils.universalPipelineOrganization.receivers[1]) + itemCount(0) + } + } + } + } + } + }.generate(ReportStreamTestDatabaseContainer.testDatabaseAccess) + + val httpRequestMessage = MockHttpRequestMessage() + + val func = setupSubmissionFunction() + + val history = func + .getReportDetailedHistory(httpRequestMessage, submittedReport.node.reportId.toString()) + assertThat(history).isNotNull() + val historyNode = JacksonMapperUtilities.defaultMapper.readTree(history.body.toString()) + assertThat( + historyNode.get("overallStatus").asText() + ).isEqualTo(DetailedSubmissionHistory.Status.PARTIALLY_DELIVERED.toString()) + assertThat(historyNode.get("destinations").size()).isEqualTo(2) + assertThat(historyNode.get("errors").size()).isEqualTo(0) + assertThat(historyNode.get("warnings").size()).isEqualTo(1) + } + + // this test remains to prevent breaking queries against old submissions that used the legacy route step + @Test + fun `it should return a history for an partially delivered submission (for legacy route step)`() { + val submittedReport = reportGraph { + topic(Topic.FULL_ELR) + format(MimeFormat.HL7) + sender(UniversalPipelineTestUtils.hl7Sender) + + submission { + action(TaskAction.receive) + reportGraphNode { + action(TaskAction.convert) + log(ActionLog(InvalidParamMessage("log"), type = ActionLogLevel.warning)) + reportGraphNode { + action(TaskAction.route) + reportGraphNode { + action(TaskAction.none) + receiver(UniversalPipelineTestUtils.universalPipelineOrganization.receivers[1]) + itemCount(0) + } + } + reportGraphNode { + action(TaskAction.route) + reportGraphNode { + action(TaskAction.translate) + receiver(UniversalPipelineTestUtils.universalPipelineOrganization.receivers[0]) + reportGraphNode { + action(TaskAction.send) + transportResult("Success") + receiver(UniversalPipelineTestUtils.universalPipelineOrganization.receivers[0]) + } + } + reportGraphNode { + action(TaskAction.none) + receiver(UniversalPipelineTestUtils.universalPipelineOrganization.receivers[1]) + itemCount(0) + } + } + } + } + }.generate(ReportStreamTestDatabaseContainer.testDatabaseAccess) + + val httpRequestMessage = MockHttpRequestMessage() + + val func = setupSubmissionFunction() + + val history = func + .getReportDetailedHistory(httpRequestMessage, submittedReport.node.reportId.toString()) + assertThat(history).isNotNull() + val historyNode = JacksonMapperUtilities.defaultMapper.readTree(history.body.toString()) + assertThat( + historyNode.get("overallStatus").asText() + ).isEqualTo(DetailedSubmissionHistory.Status.PARTIALLY_DELIVERED.toString()) + assertThat(historyNode.get("destinations").size()).isEqualTo(2) + assertThat(historyNode.get("errors").size()).isEqualTo(0) + assertThat(historyNode.get("warnings").size()).isEqualTo(1) + } + + // TODO: https://github.com/CDCgov/prime-reportstream/issues/16054 + @Test + fun `it should return a history for an in-flight submission`() { val submittedReport = reportGraph { topic(Topic.FULL_ELR) format(MimeFormat.HL7) @@ -126,15 +248,16 @@ class SubmissionFunctionIntegrationTests { val historyNode = JacksonMapperUtilities.defaultMapper.readTree(history.body.toString()) assertThat( historyNode.get("overallStatus").asText() - ).isEqualTo(DetailedSubmissionHistory.Status.PARTIALLY_DELIVERED.toString()) + ).isEqualTo(DetailedSubmissionHistory.Status.PARTIALLY_DELIVERED.toString()) // TODO: should be RECEIVED assertThat(historyNode.get("destinations").size()).isEqualTo(2) assertThat(historyNode.get("errors").size()).isEqualTo(0) assertThat(historyNode.get("warnings").size()).isEqualTo(1) } + // TODO: https://github.com/CDCgov/prime-reportstream/issues/16054 // this test remains to prevent breaking queries against old submissions that used the legacy route step @Test - fun `it should return a history for partially delivered submission (for legacy route step)`() { + fun `it should return a history for an in-flight submission (for legacy route step)`() { val submittedReport = reportGraph { topic(Topic.FULL_ELR) format(MimeFormat.HL7) @@ -184,7 +307,7 @@ class SubmissionFunctionIntegrationTests { val historyNode = JacksonMapperUtilities.defaultMapper.readTree(history.body.toString()) assertThat( historyNode.get("overallStatus").asText() - ).isEqualTo(DetailedSubmissionHistory.Status.PARTIALLY_DELIVERED.toString()) + ).isEqualTo(DetailedSubmissionHistory.Status.PARTIALLY_DELIVERED.toString()) // TODO: should be RECEIVED assertThat(historyNode.get("destinations").size()).isEqualTo(2) assertThat(historyNode.get("errors").size()).isEqualTo(0) assertThat(historyNode.get("warnings").size()).isEqualTo(1) From ecc6d505738c88a0cace7c69fa0604c2cd2e2f96 Mon Sep 17 00:00:00 2001 From: Gabriel Dorsch Date: Mon, 7 Oct 2024 12:15:54 -0400 Subject: [PATCH 2/2] Rework theNextAction members --- .../test/kotlin/common/ReportNodeBuilder.kt | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/prime-router/src/test/kotlin/common/ReportNodeBuilder.kt b/prime-router/src/test/kotlin/common/ReportNodeBuilder.kt index 340261bce85..616773f1e6d 100644 --- a/prime-router/src/test/kotlin/common/ReportNodeBuilder.kt +++ b/prime-router/src/test/kotlin/common/ReportNodeBuilder.kt @@ -25,7 +25,7 @@ class ReportGraphBuilder { private lateinit var theTopic: Topic private lateinit var theFormat: MimeFormat private lateinit var theSender: Sender - private lateinit var theNextAction: TaskAction + private var theNextAction: TaskAction? = null fun topic(topic: Topic) { this.theTopic = topic @@ -85,13 +85,7 @@ class ReportGraphBuilder { .setItemCount(theSubmission.theItemCount) .setExternalName("test-external-name") .setBodyUrl(theSubmission.theReportBlobUrl) - .setNextAction( - if (::theNextAction.isInitialized) { - theNextAction - } else { - theSubmission.reportGraphNodes.firstOrNull()?.theAction - } - ) + .setNextAction(theNextAction ?: theSubmission.reportGraphNodes.firstOrNull()?.theAction) .setCreatedAt(OffsetDateTime.now()) dbAccess.insertReportFile( reportFile, txn, action @@ -142,13 +136,7 @@ class ReportGraphBuilder { .setExternalName("test-external-name") .setBodyUrl(node.theReportBlobUrl) .setTransportResult(node.theTransportResult) - .setNextAction( - if (node.theNextAction != null) { - node.theNextAction - } else { - node.reportGraphNodes.firstOrNull()?.theAction - } - ) + .setNextAction(node.theNextAction ?: node.reportGraphNodes.firstOrNull()?.theAction) .setCreatedAt(graph.node.createdAt.plusMinutes(1)) if (node.receiver != null) {