-
Notifications
You must be signed in to change notification settings - Fork 60
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
Write Unit Tests on Related Entity Location sync strategy enchancements #3144
Changes from 7 commits
042d26c
34d19bf
a8087f8
05ebdc9
371a7c4
6f4eba4
e594e37
b8ee94c
81044f3
c4574a3
2dba444
0ba3b54
ddd6846
f484811
5462bbf
dedc3bb
bd08390
0351594
218af96
4dfa916
83053a8
64c1111
31da65b
a540f9b
dc7d9e7
de621ca
82fac15
4950520
c28d959
4fe6376
1b3719c
99df870
c449846
3406dc8
709fd2f
90209bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ import io.mockk.verify | |
import java.util.Date | ||
import java.util.UUID | ||
import javax.inject.Inject | ||
import kotlin.test.assertEquals | ||
import kotlin.time.Duration.Companion.seconds | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.runBlocking | ||
|
@@ -1143,4 +1144,123 @@ class QuestionnaireViewModelTest : RobolectricTest() { | |
bundle.entry.any { it.resource is Basic && it.resource.id == "basic-resource-id" }, | ||
) | ||
} | ||
|
||
@Test | ||
fun testApplyRelatedEntityLocationMetaTagWithResourceIdentifier() = runBlocking { | ||
val questionnaireConfig = | ||
questionnaireConfig.copy( | ||
resourceIdentifier = "resourceId", | ||
resourceType = ResourceType.Observation, | ||
saveQuestionnaireResponse = false, | ||
type = "EDIT", | ||
extractedResourceUniquePropertyExpressions = | ||
listOf( | ||
ExtractedResourceUniquePropertyExpression( | ||
ResourceType.Observation, | ||
"Observation.code.where(coding.code='obs1').coding.code", | ||
), | ||
), | ||
) | ||
val questionnaireResponse = | ||
QuestionnaireResponse().apply { | ||
id = "resourceId" | ||
meta.lastUpdated = Date() | ||
subject = patient.asReference() | ||
questionnaire = samplePatientRegisterQuestionnaire.asReference().reference | ||
} | ||
val subjectType = ResourceType.Observation | ||
|
||
assertEquals("resourceId", questionnaireResponse.id) | ||
assertEquals(subjectType, questionnaireConfig.resourceType) | ||
} | ||
|
||
@Test | ||
fun `test applyRelatedEntityLocationMetaTag with groupIdentifier`() = runBlocking { | ||
val bundleSlot = slot<Bundle>() | ||
val bundle = bundleSlot.captured | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The slot is captured here when there is no function called with the bundle as a parameter. |
||
val questionnaireConfig = | ||
questionnaireConfig.copy( | ||
resourceIdentifier = "groupId", | ||
resourceType = ResourceType.Group, | ||
saveQuestionnaireResponse = false, | ||
type = "EDIT", | ||
extractedResourceUniquePropertyExpressions = | ||
listOf( | ||
ExtractedResourceUniquePropertyExpression( | ||
ResourceType.Observation, | ||
"Observation.code.where(coding.code='obs1').coding.code", | ||
), | ||
), | ||
) | ||
bundle.entry.forEach { | ||
val resource = it.resource | ||
val subjectType = ResourceType.Group | ||
resource.id = "groupId" | ||
|
||
assertEquals(subjectType, resource.resourceType) | ||
assertEquals(questionnaireConfig.resourceIdentifier, resource.id) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertions here are not done against the metatags as the name of the test suggests. |
||
} | ||
|
||
@Test | ||
fun `test saveExtractedResources for resource modification`() = runBlocking { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are we testing here? |
||
val questionnaire = extractionQuestionnaire() | ||
val questionnaireConfig = | ||
questionnaireConfig.copy( | ||
resourceIdentifier = "groupId", | ||
resourceType = ResourceType.Group, | ||
saveQuestionnaireResponse = false, | ||
type = "EDIT", | ||
extractedResourceUniquePropertyExpressions = | ||
listOf( | ||
ExtractedResourceUniquePropertyExpression( | ||
ResourceType.Observation, | ||
"Observation.code.where(coding.code='obs1').coding.code", | ||
), | ||
), | ||
) | ||
val questionnaireResponse = | ||
QuestionnaireResponse().apply { | ||
id = "resourceId" | ||
meta.lastUpdated = Date() | ||
subject = patient.asReference() | ||
} | ||
|
||
val bundle = | ||
Bundle().apply { | ||
addEntry( | ||
Bundle.BundleEntryComponent().apply { | ||
PractitionerDetails().apply { | ||
fhirPractitionerDetails = | ||
FhirPractitionerDetails().apply { | ||
id = "practitionerId1" | ||
practitionerId = StringType("practitionerId1") | ||
} | ||
} | ||
id = "patientId1" | ||
}, | ||
) | ||
addEntry( | ||
Bundle.BundleEntryComponent().apply { | ||
PractitionerDetails().apply { | ||
fhirPractitionerDetails = | ||
FhirPractitionerDetails().apply { | ||
id = "practitionerId2" | ||
practitionerId = StringType("practitionerId2") | ||
} | ||
} | ||
id = "patientId1" | ||
}, | ||
) | ||
} | ||
questionnaireViewModel.saveExtractedResources( | ||
bundle, | ||
questionnaire, | ||
questionnaireConfig, | ||
questionnaireResponse, | ||
context, | ||
) | ||
|
||
assertEquals("patientLogicalId", questionnaireResponse.subject.reference) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add more assertions/verifications for this test? |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assertions will always be evaluated to be true. The assertions are not done against the meta tags as the name of the test suggests.