diff --git a/src/__tests__/compliance-chargeback-list.screen.test.tsx b/src/__tests__/compliance-chargeback-list.screen.test.tsx index 501d9deee..16435eebc 100644 --- a/src/__tests__/compliance-chargeback-list.screen.test.tsx +++ b/src/__tests__/compliance-chargeback-list.screen.test.tsx @@ -42,10 +42,21 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import { ChargebackBlockReason, PendingChargebackEntry } from 'src/dto/chargeback.dto'; import ComplianceChargebackListScreen from 'src/screens/compliance-chargeback-list.screen'; -const REQUESTED = new Date('2026-01-15T10:00:00.000Z'); -const DATE = new Date('2026-01-15T12:00:00.000Z'); +type PendingChargebackPayload = Omit & { + requestedDate: string; + date: string; + chargebackDate?: string; +}; + +// JSON round-trip: mirrors real HTTP transport (drops undefined keys, keeps ISO strings, breaks aliasing) +function asTransport(value: T): T { + return JSON.parse(JSON.stringify(value)) as T; +} + +const REQUESTED = '2026-01-15T10:00:00.000Z'; +const DATE = '2026-01-15T12:00:00.000Z'; -function baseEntry(overrides: Partial = {}): PendingChargebackEntry { +function baseEntry(overrides: Partial = {}): PendingChargebackEntry { return { txId: 9001, uid: 'T-9001', @@ -61,7 +72,7 @@ function baseEntry(overrides: Partial = {}): PendingChar requestedDate: REQUESTED, date: DATE, ...overrides, - }; + } as unknown as PendingChargebackEntry; } interface Deferred { @@ -90,7 +101,7 @@ describe('ComplianceChargebackListScreen', () => { beforeEach(() => { jest.clearAllMocks(); mockIsLoggedIn = true; - mockGetPendingChargebacks.mockResolvedValue([]); + mockGetPendingChargebacks.mockResolvedValue(asTransport([])); }); it('does not fetch when not logged in', () => { @@ -111,7 +122,7 @@ describe('ComplianceChargebackListScreen', () => { expect(screen.queryByRole('table')).not.toBeInTheDocument(); expect(screen.queryByTestId('error-hint')).not.toBeInTheDocument(); - deferred.resolve([]); + deferred.resolve(asTransport([])); await waitFor(() => { expect(screen.queryByTestId('loading-spinner')).not.toBeInTheDocument(); }); @@ -132,7 +143,7 @@ describe('ComplianceChargebackListScreen', () => { }); it('shows the empty-state row when the response is a successful empty list', async () => { - mockGetPendingChargebacks.mockResolvedValue([]); + mockGetPendingChargebacks.mockResolvedValue(asTransport([])); render(); @@ -194,7 +205,7 @@ describe('ComplianceChargebackListScreen', () => { entityId: 1005, blockReasons: [ChargebackBlockReason.MISSING_CREDITOR_DATA], userName: 'Sentinel User', - chargebackDate: new Date('2026-02-01T00:00:00.000Z'), + chargebackDate: '2026-02-01T00:00:00.000Z', }); const multiReason = baseEntry({ @@ -217,15 +228,17 @@ describe('ComplianceChargebackListScreen', () => { userName: 'No Reasons User', }); - mockGetPendingChargebacks.mockResolvedValue([ - plainMissing, - nameMismatch, - nameMismatchMissingNames, - userNotReleased, - sentinel, - multiReason, - noBlockReasons, - ]); + mockGetPendingChargebacks.mockResolvedValue( + asTransport([ + plainMissing, + nameMismatch, + nameMismatchMissingNames, + userNotReleased, + sentinel, + multiReason, + noBlockReasons, + ]), + ); render(); @@ -324,7 +337,7 @@ describe('ComplianceChargebackListScreen', () => { blockReasons: [ChargebackBlockReason.MISSING_CHARGEBACK_AMOUNT], }); - mockGetPendingChargebacks.mockResolvedValue([withAsset, withoutAsset, nullAmounts, zeroAmount]); + mockGetPendingChargebacks.mockResolvedValue(asTransport([withAsset, withoutAsset, nullAmounts, zeroAmount])); render(); @@ -368,7 +381,7 @@ describe('ComplianceChargebackListScreen', () => { userName: 'Empty Uid', }); - mockGetPendingChargebacks.mockResolvedValue([withUid, emptyUid]); + mockGetPendingChargebacks.mockResolvedValue(asTransport([withUid, emptyUid])); render(); @@ -386,7 +399,7 @@ describe('ComplianceChargebackListScreen', () => { entityId: 1301, userName: 'Clickable User', }); - mockGetPendingChargebacks.mockResolvedValue([entry]); + mockGetPendingChargebacks.mockResolvedValue(asTransport([entry])); render(); diff --git a/src/__tests__/compliance-pending-chargebacks.hook.test.ts b/src/__tests__/compliance-pending-chargebacks.hook.test.ts index e0c59b7e3..59f4567b5 100644 --- a/src/__tests__/compliance-pending-chargebacks.hook.test.ts +++ b/src/__tests__/compliance-pending-chargebacks.hook.test.ts @@ -36,6 +36,17 @@ jest.mock('../hooks/navigation.hook', () => ({ import { useCompliance } from '../hooks/compliance.hook'; import { ChargebackBlockReason, PendingChargebackEntry } from '../dto/chargeback.dto'; +type PendingChargebackPayload = Omit & { + requestedDate: string; + date: string; + chargebackDate?: string; +}; + +// JSON round-trip: mirrors real HTTP transport (drops undefined keys, keeps ISO strings, breaks aliasing) +function asTransport(value: T): T { + return JSON.parse(JSON.stringify(value)) as T; +} + describe('useCompliance().getPendingChargebacks', () => { beforeEach(() => { // react-scripts sets resetMocks:true, which wipes implementations before each test @@ -43,7 +54,7 @@ describe('useCompliance().getPendingChargebacks', () => { }); it('issues GET support/pending-chargebacks and returns the payload', async () => { - const payload: PendingChargebackEntry[] = [ + const payload: PendingChargebackPayload[] = [ { txId: 9001, uid: 'T-9001', @@ -56,11 +67,11 @@ describe('useCompliance().getPendingChargebacks', () => { chargebackAmount: 100, chargebackAsset: 'EUR', blockReasons: [ChargebackBlockReason.MISSING_CHARGEBACK_AMOUNT], - requestedDate: new Date('2026-01-15T10:00:00.000Z'), - date: new Date('2026-01-15T10:00:00.000Z'), + requestedDate: '2026-01-15T10:00:00.000Z', + date: '2026-01-15T10:00:00.000Z', }, ]; - mockCall.mockResolvedValue(payload); + mockCall.mockResolvedValue(asTransport(payload)); const { result } = renderHook(() => useCompliance()); @@ -72,5 +83,6 @@ describe('useCompliance().getPendingChargebacks', () => { method: 'GET', }); expect(entries).toEqual(payload); + expect(entries[0].requestedDate).toBe('2026-01-15T10:00:00.000Z'); }); });