Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases for partially delivered submissions #16055

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions prime-router/src/test/kotlin/common/ReportNodeBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the TODO?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the todo in the function header (#16054)

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)
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the TODO?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the todo in the function header (#16054)

assertThat(historyNode.get("destinations").size()).isEqualTo(2)
assertThat(historyNode.get("errors").size()).isEqualTo(0)
assertThat(historyNode.get("warnings").size()).isEqualTo(1)
Expand Down