Skip to content

d3628eb0 - Mock chargeback API dates as ISO strings in unit tests - #1300

Merged
TaprootFreak merged 2 commits into
developfrom
fix/chargeback-test-mock-fidelity
Aug 10, 2026
Merged

d3628eb0 - Mock chargeback API dates as ISO strings in unit tests#1300
TaprootFreak merged 2 commits into
developfrom
fix/chargeback-test-mock-fidelity

Conversation

@TaprootFreak

@TaprootFreak TaprootFreak commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Why

Follow-up to #1285 (see #1285 (comment)): the unit tests mock the API payload with Date instances, but over JSON transport requestedDate/date/chargebackDate arrive as ISO strings. The rendering path handles both today, yet the tests would stay green through a regression that only breaks on string input.

What

  • Introduce a local transport-shaped PendingChargebackPayload type (dates as string, mirroring the e2e spec's fixtures) in both test files.
  • Screen test: the fixture date constants and the sentinel chargebackDate are ISO strings now; baseEntry() builds the transport shape and casts once at the mock boundary.
  • Hook test: the mocked payload is typed transport-shaped; no cast needed at the untyped jest.fn() boundary.
  • Every successful mock payload is routed through a JSON round-trip helper (asTransport) at the mock boundary — mirroring what response.json() actually delivers: keys set to undefined are dropped, and the resolved value is a fresh clone, so reference aliasing cannot mask an in-place mutation. Rejection paths stay untouched. The hook test additionally asserts the raw ISO string on the result.
  • No production code changes.

Both suites pass locally (2 suites, 9 tests).

The unit tests for the pending-chargeback screen and hook mocked the API
payload with Date instances, but over JSON transport these fields arrive
as ISO strings. The rendering path handles both, yet the tests could stay
green through a regression that only breaks on string input.

Introduce a transport-shaped payload type (dates as strings, mirroring
the e2e spec fixtures) and cast once at the mock boundary, so the tests
exercise the same data shape the real backend delivers.
Route every successful mock payload through a JSON round-trip helper.
This mirrors what response.json() actually delivers: keys set to
undefined are dropped instead of being present, and the resolved value
is no longer the same object reference as the fixture, so an in-place
mutation inside the hook chain can no longer hide behind toEqual.
Also assert the raw ISO string on the hook result explicitly.
@TaprootFreak

Copy link
Copy Markdown
Contributor Author

Two review passes to zero findings. Pass 1 flagged two gaps in the new fixtures: the hook test compared the result against the very object reference it had fed into the mock, and some fixtures set keys to an explicit undefined, which a real JSON response never contains. Both are addressed by routing every successful mock payload through a JSON round-trip at the mock boundary and asserting the raw ISO string on the hook result.

@TaprootFreak
TaprootFreak marked this pull request as ready for review August 10, 2026 11:22
@TaprootFreak
TaprootFreak merged commit 1e45834 into develop Aug 10, 2026
6 checks passed
@TaprootFreak
TaprootFreak deleted the fix/chargeback-test-mock-fidelity branch August 10, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant