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
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,86 @@ describe('spend-request', () => {
});
});

describe('card summary', () => {
it('RetrieveSpendRequest shows card_brand and card_last4 when full card is not expanded', async () => {
const request = makeSpendRequest({
merchant_name: 'Acme',
card_brand: 'visa',
card_last4: '4242',
});
const repo = makeMockRepo(request);

const { lastFrame } = render(
<RetrieveSpendRequest
repository={repo}
id="sr_test"
onComplete={() => {}}
/>,
);

await vi.waitFor(() => {
const frame = lastFrame();
expect(frame).toContain('Card:');
expect(frame).toContain('visa');
expect(frame).toContain('····4242');
});
});

it('RetrieveSpendRequest hides the card summary when the full card is expanded', async () => {
const request = makeSpendRequest({
merchant_name: 'Acme',
card_brand: 'visa',
card_last4: '4242',
card: {
id: 'ic_1',
brand: 'visa',
exp_month: 12,
exp_year: 2030,
number: '4242424242424242',
},
});
const repo = makeMockRepo(request);

const { lastFrame } = render(
<RetrieveSpendRequest
repository={repo}
id="sr_test"
onComplete={() => {}}
/>,
);

await vi.waitFor(() => {
const frame = lastFrame();
expect(frame).toContain('Card Details:');
expect(frame).not.toContain('····4242');
});
});

it('RetrieveSpendRequest omits the card summary for SPT (no brand/last4)', async () => {
const request = makeSpendRequest({
merchant_name: 'Acme',
credential_type: 'shared_payment_token',
card_brand: undefined,
card_last4: undefined,
});
const repo = makeMockRepo(request);

const { lastFrame } = render(
<RetrieveSpendRequest
repository={repo}
id="sr_test"
onComplete={() => {}}
/>,
);

await vi.waitFor(() => {
const frame = lastFrame();
expect(frame).toContain('Spend request approved');
expect(frame).not.toContain('Card:');
});
});
});

describe('sanitization', () => {
it('CreateSpendRequest sanitizes merchant_name and line_items', async () => {
const request = makeSpendRequest();
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/src/commands/spend-request/retrieve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,24 @@ export const RetrieveSpendRequest: React.FC<RetrieveSpendRequestProps> = ({
)}
</Box>
)}
{!request?.card && (request?.card_brand || request?.card_last4) && (
<Box flexDirection="column" marginTop={1}>
<Text bold>Card:</Text>
<Text>
{' '}
{[
request?.card_brand,
request?.card_last4 && `····${request.card_last4}`,
]
.filter(Boolean)
.join(' ')}
</Text>
<Text color="gray">
{' '}
Use --include card to expand full card details
</Text>
</Box>
)}
{request?.card && outputFile && (
<Box flexDirection="column" marginTop={1}>
{outputFilePath && (
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export interface SpendRequest {
payment_details: string;
credential_type?: CredentialType;
network_id?: string;
card_brand?: string;
card_last4?: string;
status: SpendRequestStatus;
approval_url?: string;
card?: Card;
Expand Down
Loading