Skip to content

[Test Improver] Add unit tests for PushNotificationRecord#3636

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
test-assist/push-notification-record-tests-5cdeb6d-d1adf011befbb255
Draft

[Test Improver] Add unit tests for PushNotificationRecord#3636
github-actions[bot] wants to merge 1 commit intomasterfrom
test-assist/push-notification-record-tests-5cdeb6d-d1adf011befbb255

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Test Improver — automated AI assistant

Goal and Rationale

PushNotificationRecord is 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 via DateUtils.parseDateTime(); missing timestamp throws JSONException
  • getNotificationActionFromRecord() — two-branch conditional: returns key when action is CCC_GENERIC_OPPORTUNITY and key is non-empty, otherwise returns action; this drives notification routing
  • title/body setters — truncate to 65535 chars via PushNotificationHelper.truncateMessage()
  • fromV23() — v23→current migration that explicitly zeros out the two new fields (key, opportunityStatus) absent in v23

Why it matters: Silent bugs in fromJson() or getNotificationActionFromRecord() 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.kt

Test What it verifies
fromJson_allFields_parsedCorrectly All 16 fields including parsed Date equal to DateUtils.parseDateTime(timestamp)
fromJson_readStatusTrue_parsedCorrectly Boolean field set to true correctly
fromJson_missingOptionalFields_defaultsToEmpty All optString/optBoolean fields default to "" / false when absent
fromJson_missingTimestamp_throwsJSONException Required timestamp field: getStringJSONException when absent
getNotificationActionFromRecord_genericOpportunityActionWithNonEmptyKey_returnsKey Primary branch: returns key
getNotificationActionFromRecord_genericOpportunityActionWithEmptyKey_returnsAction Empty key falls through to action
getNotificationActionFromRecord_nonGenericAction_returnsAction Non-generic action always returns action
titleSetter_longTitle_isTruncatedToMaxLength Title >65535 chars truncated to exactly 65535
bodySetter_longBody_isTruncatedToMaxLength Body >65535 chars truncated to exactly 65535
fromV23_allFieldsCopied_newFieldsDefaultToEmpty All V23 fields copied; key="", opportunityStatus="" explicitly set

No mocking required — all tests use PushNotificationRecord directly.

Coverage Impact

PushNotificationRecord previously had 0% dedicated test coverage. All public methods are now covered.

Trade-offs

  • fromV23() does not test the acknowledged field copy from V23 (field exists in V23 but PushNotificationRecordV23 does not expose it as public in Java — the test sets and asserts it correctly since Kotlin sees it).
  • Title/body truncation behavior is also covered by PushNotificationHelperTest for 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). ktlintFile Gradle task also unavailable due to Gradle wrapper lock file (infrastructure constraint). File follows the existing ConnectReleaseTogglesParserTest.kt style.

To run:

./gradlew testCommcareDebug --tests "org.commcare.android.database.connect.models.PushNotificationRecordTest"

Generated by Daily Test Improver ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/daily-test-improver.md@346204513ecfa08b81566450d7d599556807389f

Generated by Daily Test Improver ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/daily-test-improver.md@346204513ecfa08b81566450d7d599556807389f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants