Skip to content

[MS-799] Simplify CommCareIdentityDataSourceTest#1479

Merged
BurningAXE merged 1 commit into
mainfrom
MS-799-Simplify-CommCareIdentityDataSourceTest
Dec 8, 2025
Merged

[MS-799] Simplify CommCareIdentityDataSourceTest#1479
BurningAXE merged 1 commit into
mainfrom
MS-799-Simplify-CommCareIdentityDataSourceTest

Conversation

@BurningAXE
Copy link
Copy Markdown
Contributor

JIRA ticket
Will be released in: 2026.1.0

Notable changes

  • Extracts several repeating patterns to avoid redundancy

Testing guidance

  • Run the tests :D

Additional work checklist

  • Effect on other features and security has been considered
  • Design document marked as "In development" (if applicable)
  • External (Gitbook) and internal (Confluence) Documentation is up to date (or ticket created)
  • Test cases in Testiny are up to date (or ticket created)
  • Other teams notified about the changes (if applicable)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors CommCareIdentityDataSourceTest by extracting repeating test setup and verification patterns into helper methods, significantly reducing code duplication and improving maintainability.

Key changes:

  • Extracted 6 helper methods for common test operations: cursor setup, assertion logic, and verification steps
  • Simplified all test methods by replacing repetitive mock setups and assertions with concise helper calls
  • Maintained the same test coverage and behavior while improving readability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@BurningAXE BurningAXE force-pushed the MS-799-Simplify-CommCareIdentityDataSourceTest branch from d5d7011 to 0698270 Compare December 1, 2025 14:22
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 1, 2025

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment on lines +251 to +286
private fun assertFingerprintIdentitiesMatch(
expected: List<Identity>,
actual: List<Identity>,
templateFormat: String,
) {
val areContentsEqual = expected
.filter { identity -> identity.samples.any { it.format == templateFormat } }
.zip(actual) { exp, act ->
exp.subjectId == act.subjectId &&
exp.samples
.zip(act.samples) { expSample, actSample ->
expSample.identifier == actSample.identifier &&
expSample.template.contentEquals(actSample.template) &&
expSample.format == actSample.format
}.all { it }
}.all { it }
assertTrue(areContentsEqual)
}

private fun assertFaceIdentitiesMatch(
expected: List<Identity>,
actual: List<Identity>,
templateFormat: String,
) {
val areContentsEqual = expected
.filter { identity -> identity.samples.any { it.format == templateFormat } }
.zip(actual) { exp, act ->
exp.subjectId == act.subjectId &&
exp.samples
.zip(act.samples) { expSample, actSample ->
expSample.template.contentEquals(actSample.template) &&
expSample.format == actSample.format
}.all { it }
}.all { it }
assertTrue(areContentsEqual)
}
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The assertion logic in both assertFingerprintIdentitiesMatch and assertFaceIdentitiesMatch has a potential bug: if the filtered expected list has a different size than the actual list, the .zip() operation will silently truncate to the shorter list, potentially missing identities that should have been asserted. This could hide bugs where fewer identities are returned than expected. Consider adding a size check: assertEquals(expected.filter { ... }.size, actual.size) before the zip operation.

Copilot uses AI. Check for mistakes.
Comment on lines +251 to +286
private fun assertFingerprintIdentitiesMatch(
expected: List<Identity>,
actual: List<Identity>,
templateFormat: String,
) {
val areContentsEqual = expected
.filter { identity -> identity.samples.any { it.format == templateFormat } }
.zip(actual) { exp, act ->
exp.subjectId == act.subjectId &&
exp.samples
.zip(act.samples) { expSample, actSample ->
expSample.identifier == actSample.identifier &&
expSample.template.contentEquals(actSample.template) &&
expSample.format == actSample.format
}.all { it }
}.all { it }
assertTrue(areContentsEqual)
}

private fun assertFaceIdentitiesMatch(
expected: List<Identity>,
actual: List<Identity>,
templateFormat: String,
) {
val areContentsEqual = expected
.filter { identity -> identity.samples.any { it.format == templateFormat } }
.zip(actual) { exp, act ->
exp.subjectId == act.subjectId &&
exp.samples
.zip(act.samples) { expSample, actSample ->
expSample.template.contentEquals(actSample.template) &&
expSample.format == actSample.format
}.all { it }
}.all { it }
assertTrue(areContentsEqual)
}
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The assertion methods assertFingerprintIdentitiesMatch and assertFaceIdentitiesMatch have significant code duplication and provide unhelpful error messages. When assertTrue(areContentsEqual) fails, developers won't know which specific field mismatched. Consider consolidating these into a single parameterized method or using a more descriptive assertion library like AssertJ that would provide detailed diff output on failure.

Copilot uses AI. Check for mistakes.
@BurningAXE BurningAXE marked this pull request as ready for review December 1, 2025 14:50
@BurningAXE BurningAXE requested review from a team, TristramN, alex-vt, alexandr-simprints, luhmirin-s, meladRaouf and ybourgery and removed request for a team December 1, 2025 14:51
@BurningAXE BurningAXE merged commit 82e9fc1 into main Dec 8, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants