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

Write Unit Tests on Related Entity Location sync strategy enchancements #3144

Merged
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
042d26c
test applyRelatedEntityLocationMetaTag with group identifier and reso…
brandyodhiambo Mar 14, 2024
34d19bf
completes the test
brandyodhiambo Mar 15, 2024
a8087f8
runs spotless
brandyodhiambo Mar 15, 2024
05ebdc9
runs spotless
brandyodhiambo Mar 15, 2024
371a7c4
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
sharon2719 Mar 15, 2024
6f4eba4
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Mar 18, 2024
e594e37
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Mar 19, 2024
b8ee94c
re writting the tests
brandyodhiambo Mar 19, 2024
81044f3
adds assertion to the test
brandyodhiambo Mar 21, 2024
c4574a3
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Mar 21, 2024
2dba444
Merge remote-tracking branch 'origin/Unit_Tests_on_Related_Entity_Loc…
brandyodhiambo Mar 21, 2024
0ba3b54
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Mar 22, 2024
ddd6846
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Mar 25, 2024
f484811
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Mar 25, 2024
5462bbf
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Mar 26, 2024
dedc3bb
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Mar 27, 2024
bd08390
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Mar 28, 2024
0351594
edits isRelatedEntityLocationMetaTagAddedToExtractedResource test
brandyodhiambo Apr 2, 2024
218af96
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Apr 2, 2024
4dfa916
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Apr 3, 2024
83053a8
makes assertion based on linkid
brandyodhiambo Apr 3, 2024
64c1111
Merge remote-tracking branch 'origin/Unit_Tests_on_Related_Entity_Loc…
brandyodhiambo Apr 3, 2024
31da65b
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Apr 4, 2024
a540f9b
make assertion for resource meta tag
brandyodhiambo Apr 16, 2024
dc7d9e7
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Apr 16, 2024
de621ca
run spotless check
brandyodhiambo Apr 16, 2024
82fac15
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Apr 16, 2024
4950520
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
sharon2719 Apr 18, 2024
c28d959
Update android/quest/src/test/java/org/smartregister/fhircore/quest/u…
brandyodhiambo Apr 18, 2024
4fe6376
Merge branch 'main' into Unit_Tests_on_Related_Entity_Location_sync_s…
brandyodhiambo Apr 18, 2024
1b3719c
add assertion for metatag ids
brandyodhiambo Apr 18, 2024
99df870
add assertion for metatag id
brandyodhiambo Apr 18, 2024
c449846
Merge remote-tracking branch 'origin/Unit_Tests_on_Related_Entity_Loc…
brandyodhiambo Apr 18, 2024
3406dc8
run spotless check
brandyodhiambo Apr 18, 2024
709fd2f
replaces the assertion
brandyodhiambo Apr 19, 2024
90209bf
replaces the assertion to a manual check
brandyodhiambo Apr 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Collaborator

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.

}

@Test
fun `test applyRelatedEntityLocationMetaTag with groupIdentifier`() = runBlocking {
val bundleSlot = slot<Bundle>()
val bundle = bundleSlot.captured
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add more assertions/verifications for this test?

}
}
Loading