d3628eb0 - Mock chargeback API dates as ISO strings in unit tests - #1300
Merged
Conversation
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.
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 |
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.
Why
Follow-up to #1285 (see #1285 (comment)): the unit tests mock the API payload with
Dateinstances, but over JSON transportrequestedDate/date/chargebackDatearrive 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
PendingChargebackPayloadtype (dates asstring, mirroring the e2e spec's fixtures) in both test files.chargebackDateare ISO strings now;baseEntry()builds the transport shape and casts once at the mock boundary.jest.fn()boundary.asTransport) at the mock boundary — mirroring whatresponse.json()actually delivers: keys set toundefinedare 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.Both suites pass locally (2 suites, 9 tests).