Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions src/__tests__/compliance-chargeback-list.screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<PendingChargebackEntry, 'requestedDate' | 'date' | 'chargebackDate'> & {
requestedDate: string;
date: string;
chargebackDate?: string;
};

// JSON round-trip: mirrors real HTTP transport (drops undefined keys, keeps ISO strings, breaks aliasing)
function asTransport<T>(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> = {}): PendingChargebackEntry {
function baseEntry(overrides: Partial<PendingChargebackPayload> = {}): PendingChargebackEntry {
return {
txId: 9001,
uid: 'T-9001',
Expand All @@ -61,7 +72,7 @@ function baseEntry(overrides: Partial<PendingChargebackEntry> = {}): PendingChar
requestedDate: REQUESTED,
date: DATE,
...overrides,
};
} as unknown as PendingChargebackEntry;
}

interface Deferred<T> {
Expand Down Expand Up @@ -90,7 +101,7 @@ describe('ComplianceChargebackListScreen', () => {
beforeEach(() => {
jest.clearAllMocks();
mockIsLoggedIn = true;
mockGetPendingChargebacks.mockResolvedValue([]);
mockGetPendingChargebacks.mockResolvedValue(asTransport([]));
});

it('does not fetch when not logged in', () => {
Expand All @@ -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();
});
Expand All @@ -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(<ComplianceChargebackListScreen />);

Expand Down Expand Up @@ -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({
Expand All @@ -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(<ComplianceChargebackListScreen />);

Expand Down Expand Up @@ -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(<ComplianceChargebackListScreen />);

Expand Down Expand Up @@ -368,7 +381,7 @@ describe('ComplianceChargebackListScreen', () => {
userName: 'Empty Uid',
});

mockGetPendingChargebacks.mockResolvedValue([withUid, emptyUid]);
mockGetPendingChargebacks.mockResolvedValue(asTransport([withUid, emptyUid]));

render(<ComplianceChargebackListScreen />);

Expand All @@ -386,7 +399,7 @@ describe('ComplianceChargebackListScreen', () => {
entityId: 1301,
userName: 'Clickable User',
});
mockGetPendingChargebacks.mockResolvedValue([entry]);
mockGetPendingChargebacks.mockResolvedValue(asTransport([entry]));

render(<ComplianceChargebackListScreen />);

Expand Down
20 changes: 16 additions & 4 deletions src/__tests__/compliance-pending-chargebacks.hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,25 @@ jest.mock('../hooks/navigation.hook', () => ({
import { useCompliance } from '../hooks/compliance.hook';
import { ChargebackBlockReason, PendingChargebackEntry } from '../dto/chargeback.dto';

type PendingChargebackPayload = Omit<PendingChargebackEntry, 'requestedDate' | 'date' | 'chargebackDate'> & {
requestedDate: string;
date: string;
chargebackDate?: string;
};

// JSON round-trip: mirrors real HTTP transport (drops undefined keys, keeps ISO strings, breaks aliasing)
function asTransport<T>(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
mockCall.mockReset().mockResolvedValue([]);
});

it('issues GET support/pending-chargebacks and returns the payload', async () => {
const payload: PendingChargebackEntry[] = [
const payload: PendingChargebackPayload[] = [
{
txId: 9001,
uid: 'T-9001',
Expand All @@ -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());

Expand All @@ -72,5 +83,6 @@ describe('useCompliance().getPendingChargebacks', () => {
method: 'GET',
});
expect(entries).toEqual(payload);
expect(entries[0].requestedDate).toBe('2026-01-15T10:00:00.000Z');
});
});
Loading