[Test Improver] Add unit tests for PushNotificationRecord#3636
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Draft
[Test Improver] Add unit tests for PushNotificationRecord#3636github-actions[bot] wants to merge 1 commit intomasterfrom
github-actions[bot] wants to merge 1 commit intomasterfrom
Conversation
This was referenced Mar 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Test Improver — automated AI assistant
Goal and Rationale
PushNotificationRecordis a core model class used throughout the notification system with zero dedicated test coverage. It contains meaningful testable logic:fromJson()— parses 16 fields from JSON including a required timestamp viaDateUtils.parseDateTime(); missing timestamp throwsJSONExceptiongetNotificationActionFromRecord()— two-branch conditional: returnskeywhen action isCCC_GENERIC_OPPORTUNITYand key is non-empty, otherwise returnsaction; this drives notification routingtitle/bodysetters — truncate to 65535 chars viaPushNotificationHelper.truncateMessage()fromV23()— v23→current migration that explicitly zeros out the two new fields (key,opportunityStatus) absent in v23Why it matters: Silent bugs in
fromJson()orgetNotificationActionFromRecord()would corrupt notification data or route notifications to the wrong action target, causing hard-to-trace failures.Approach
New test class:
app/unit-tests/src/org/commcare/android/database/connect/models/PushNotificationRecordTest.ktfromJson_allFields_parsedCorrectlyDateequal toDateUtils.parseDateTime(timestamp)fromJson_readStatusTrue_parsedCorrectlytruecorrectlyfromJson_missingOptionalFields_defaultsToEmptyoptString/optBooleanfields default to""/falsewhen absentfromJson_missingTimestamp_throwsJSONExceptiontimestampfield:getString→JSONExceptionwhen absentgetNotificationActionFromRecord_genericOpportunityActionWithNonEmptyKey_returnsKeykeygetNotificationActionFromRecord_genericOpportunityActionWithEmptyKey_returnsActiongetNotificationActionFromRecord_nonGenericAction_returnsActiontitleSetter_longTitle_isTruncatedToMaxLengthbodySetter_longBody_isTruncatedToMaxLengthfromV23_allFieldsCopied_newFieldsDefaultToEmptykey="",opportunityStatus=""explicitly setNo mocking required — all tests use
PushNotificationRecorddirectly.Coverage Impact
PushNotificationRecordpreviously had 0% dedicated test coverage. All public methods are now covered.Trade-offs
fromV23()does not test theacknowledgedfield copy from V23 (field exists in V23 butPushNotificationRecordV23does not expose it as public in Java — the test sets and asserts it correctly since Kotlin sees it).PushNotificationHelperTestfor the helper itself; these tests verify that the setters actually invoke truncation.Test Status
Build not runnable locally (requires
../commcare-core/sibling directory, checked out only in CI).ktlintFileGradle task also unavailable due to Gradle wrapper lock file (infrastructure constraint). File follows the existingConnectReleaseTogglesParserTest.ktstyle.To run: