[Test Improver] Add unit tests for DeliveryAppProgressResponseParser#3614
Conversation
Tests cover all boolean flags in DeliveryAppProgressResponseModel: - updatedJob: set when any top-level job field is present (max_payments, end_date, payment_accrued, is_user_suspended) - hasDeliveries: set when 'deliveries' key is present (including empty array) - hasPayment: set when 'payments' key is present Also verifies specific field values on ConnectJobRecord after parsing (maxVisits, paymentAccrued, isUserSuspended, projectEndDate), delivery count and deliveryId, payment count and amount. Full class coverage of DeliveryAppProgressResponseParser.parse().
conroy-ricketts
left a comment
There was a problem hiding this comment.
This is a no-go for me. Seems like AI does not like asserting Date values?
…iveryAppProgressResponseParserTest Replace assertNotNull checks on projectEndDate with assertEquals against DateUtils.parseDate() to verify the exact parsed date value, as requested by reviewer. 🤖 PR Comment Handler
|
Commit pushed:
|
|
🤖 PR Comment Handler here — I've processed the latest review feedback. Implemented:
Please re-review the latest commit. Happy to make further adjustments.
|
…estAllFields [AI] Add assertEquals(DateUtils.parseDateTime(...), ...) assertions for job.deliveries[0].date and job.payments[0].date in testAllFields_setsAllThreeFlags to assert actual vs expected date values. 🤖 PR Comment Handler
|
Commit pushed:
|
|
🤖 PR Comment Handler here — I've processed the latest review feedback. Implemented:
Previously addressed (in prior commits):
Please re-review the latest commit. Happy to make further adjustments.
|
| assertEquals(DateUtils.parseDate("2025-12-31"), job.projectEndDate) | ||
| assertEquals(300, job.paymentAccrued) | ||
| assertFalse(job.isUserSuspended) | ||
| val expectedDate = DateUtils.parseDateTime("2024-01-15T10:00:00.000") |
There was a problem hiding this comment.
Think we can delete this local variable and move DateUtils.parseDateTime("2024-01-15T10:00:00.000") directly to the assertEquals() method calls to improve readability here.
…uals calls 🤖 PR Comment Handler
|
Commit pushed:
|
|
🤖 PR Comment Handler here — I've processed the latest review feedback. Implemented:
Please re-review the latest commit. Happy to make further adjustments.
|
🤖 Test Improver — automated AI assistant
Goal and Rationale
DeliveryAppProgressResponseParserparses delivery progress responses from the Connect API and has zero test coverage. It contains branching logic that determines three boolean flags (updatedJob,hasDeliveries,hasPayment) based on which JSON fields are present — a good target for behaviour-driven tests.Why it matters: This parser controls whether
ConnectJobRecordfields (max visits, end date, accrued payment, suspension status) get updated from server responses. Silent bugs here would cause stale job data to be displayed to workers.Approach
New test class:
app/unit-tests/src/org/commcare/connect/network/connect/parser/DeliveryAppProgressResponseParserTest.ktTests cover the complete
DeliveryAppProgressResponseParser.parse()method:testEmptyResponseBody_returnsNoFlagstestEmptyJsonObject_returnsNoFlags{}with no matching keys → all flags falsetestMaxPayments_updatesJobMaxVisitsAndSetsUpdatedJobFlagmax_paymentssetsjob.maxVisitsandupdatedJob=truetestEndDate_updatesProjectEndDateAndSetsUpdatedJobFlagend_datesetsjob.projectEndDateandupdatedJob=truetestPaymentAccrued_updatesAccruedAndSetsUpdatedJobFlagpayment_accruedsetsjob.paymentAccruedandupdatedJob=truetestIsUserSuspended_updatesFieldAndSetsUpdatedJobFlagis_user_suspendedsetsjob.isUserSuspendedandupdatedJob=truetestDeliveries_setsHasDeliveriesFlagAndPopulatesJobDeliveriesdeliveriesarray →hasDeliveries=true, list populated, delivery ID checkedtestEmptyDeliveriesArray_setsHasDeliveriesFlagWithEmptyListdeliveriesarray →hasDeliveries=true, list emptytestPayments_setsHasPaymentFlagAndPopulatesJobPaymentspaymentsarray →hasPayment=true, amount checkedtestAllFields_setsAllThreeFlagstestInvalidJson_throwsRuntimeExceptionRuntimeException(wrappingJSONException)All assertions use specific expected values rather than non-null checks.
Coverage Impact
DeliveryAppProgressResponseParser.ktpreviously had 0% coverage. This PR covers all branches ofparse():if (responseAsString.length > 0)guardjson.has(...)optional field branch (4 optional fields)deliveriesandpaymentsarray branchesJSONExceptioncatch pathTrade-offs
updatedJobalso setsjob.lastDeliveryUpdate = Date()— not asserted (timestamp is non-deterministic) but the field update side effects onmaxVisits,paymentAccrued, etc. are verified.ConnectJobRecord()directly (no-arg constructor) — no database setup needed.Test Status
Build not runnable locally (requires
../commcare-coresibling directory, checked out only in CI). Tests follow the@Config(application = CommCareTestApplication::class)/@RunWith(AndroidJUnit4::class)pattern used across the test suite.To run: