-
Notifications
You must be signed in to change notification settings - Fork 59
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
Write Unit Tests on Related Entity Location sync strategy enchancements #3144
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3144 +/- ##
=========================================
+ Coverage 29.6% 30.1% +0.4%
- Complexity 658 672 +14
=========================================
Files 239 239
Lines 11204 11231 +27
Branches 1948 1953 +5
=========================================
+ Hits 3323 3384 +61
+ Misses 7447 7406 -41
- Partials 434 441 +7
Flags with carried forward coverage won't be shown. Click here to find out more. |
…trategy_enchancements
…trategy_enchancements
…trategy_enchancements
assertEquals("resourceId", questionnaireResponse.id) | ||
assertEquals(subjectType, questionnaireConfig.resourceType) |
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.
val bundleSlot = slot<Bundle>() | ||
val bundle = bundleSlot.captured |
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.
The slot is captured here when there is no function called with the bundle as a parameter.
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 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 { |
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.
What are we testing here?
context, | ||
) | ||
|
||
assertEquals("patientLogicalId", questionnaireResponse.subject.reference) |
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.
Can you add more assertions/verifications for this test?
Use the same naming convention for the test cases. See the documentation on OpenSRP docs |
@brandy-kay The tests should be re-written to verify and assert that related entity location meta tag is indeed added to the extracted resources from a questionnaire submission. To achieve this, the questionnaire needs to include a field that will be used to capture the location uuid. The link Id of this field is required to be configured in the Questionnaire Config. Refer to the code changes made in the PR 3097 referenced in the issue. |
…trategy_enchancements
…ation_sync_strategy_enchancements' into Unit_Tests_on_Related_Entity_Location_sync_strategy_enchancements
@ellykits Have made some improvements on the test could you please have a look at it |
…trategy_enchancements
…trategy_enchancements
…trategy_enchancements
…trategy_enchancements
…trategy_enchancements
…trategy_enchancements
…trategy_enchancements
…trategy_enchancements
…ation_sync_strategy_enchancements' into Unit_Tests_on_Related_Entity_Location_sync_strategy_enchancements
…trategy_enchancements
val listResource = questionnaireResponse.contained.firstOrNull() as ListResource | ||
assertEquals(listResource.id, linkId) |
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.
Can you assert that the Related Entity Location resource meta tag was added to the resource meat property?
@ellykits have added assertion for the related entity resource meta tag |
…trategy_enchancements
...rc/test/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModelTest.kt
Outdated
Show resolved
Hide resolved
val listResource = questionnaireResponse.contained.firstOrNull() as ListResource | ||
assertEquals(listResource.id, linkId) | ||
val resource = listResource.entry.firstOrNull()?.item?.resource | ||
if (resource != null) { |
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.
Instead of this condition use assertNotNull(
…i/questionnaire/QuestionnaireViewModelTest.kt Co-authored-by: Martin Ndegwa <[email protected]>
subject = patient.asReference() | ||
val listResource = | ||
ListResource().apply { | ||
id = UUID.randomUUID().toString() |
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.
Use a dummy test uuid so that you can use it in the assert as well (to confirm it is actually the correct one added)
if (resource != null) { | ||
assertTrue( | ||
resource.meta?.tag?.any { | ||
it.system == "https://smartregister.org/related-entity-location-tag-id" |
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.
Assert the REL UUID as well
…trategy_enchancements
…ation_sync_strategy_enchancements' into Unit_Tests_on_Related_Entity_Location_sync_strategy_enchancements
Assert.assertNotNull( | ||
resource?.meta?.tag?.any { it.code == metaTagId }, | ||
) | ||
Assert.assertNotNull( | ||
resource?.meta?.tag?.any { | ||
it.system == "https://smartregister.org/related-entity-location-tag-id" |
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.
The any(
method of the Iterable interface will always return a Boolean, so this test will always pass regardless of the values checked.
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.
In my previous comment for the assertNotNull
was only to replace the if condition that was there previously
…ts (#3144) Add unit test to verify SaveExtractedResources Adds RelatedEntityLocation Meta Tag To Extracted Resources
…urce identifierIMPORTANT: Where possible all PRs must be linked to a Github issue
Fixes #3105
Engineer Checklist
strings.xml
file./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the project's style guideCode Reviewer Checklist
strings.xml
file