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
5 changes: 5 additions & 0 deletions .changeset/soft-otters-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stripe/link-cli": patch
---

Fix `spend-request create --approve` showing the approval-waiting screen and QR code even though the request is already approved.
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,67 @@ describe('spend-request', () => {
});
});

describe('approve', () => {
it('CreateSpendRequest skips the approval-waiting/QR view when the request is already approved', async () => {
const request = makeSpendRequest({ status: 'approved' });
const repo = makeMockRepo(request);

const { lastFrame } = render(
<CreateSpendRequest
repository={repo}
params={{
payment_details: 'pm_1',
amount: 1000,
currency: 'usd',
merchant_name: 'Acme',
merchant_url: 'https://example.com',
context: 'x'.repeat(100),
}}
requestApproval
approve
onComplete={() => {}}
/>,
);

await vi.waitFor(() => {
const frame = lastFrame();
expect(frame).toContain('Spend request created');
expect(frame).not.toContain('Approve at:');
expect(frame).not.toContain('Get the Link app');
});
});

it('CreateSpendRequest still shows the approval-waiting/QR view when requestApproval is set and the request is not yet approved', async () => {
const created = makeSpendRequest({
status: 'created',
approval_url: 'https://app.link.com/approve/sr_test',
});
const repo = makeMockRepo(created);

const { lastFrame } = render(
<CreateSpendRequest
repository={repo}
params={{
payment_details: 'pm_1',
amount: 1000,
currency: 'usd',
merchant_name: 'Acme',
merchant_url: 'https://example.com',
context: 'x'.repeat(100),
}}
requestApproval
onComplete={() => {}}
/>,
);

await vi.waitFor(() => {
const frame = lastFrame();
expect(frame).toContain('Approve at:');
expect(frame).toContain('Get the Link app');
});
});
});

describe('requires_action', () => {
it('CreateSpendRequest shows next_action details for a non-auto_resume type', async () => {
const request = makeSpendRequest({
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/commands/spend-request/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface CreateSpendRequestProps {
repository: ISpendRequestResource;
params: CreateSpendRequestParams;
requestApproval?: boolean;
approve?: boolean;
outputFile?: string;
force?: boolean;
onComplete: (result: SpendRequest | null) => void;
Expand All @@ -35,6 +36,7 @@ export const CreateSpendRequest: React.FC<CreateSpendRequestProps> = ({
repository,
params,
requestApproval = false,
approve = false,
outputFile,
force,
onComplete,
Expand Down Expand Up @@ -210,7 +212,7 @@ export const CreateSpendRequest: React.FC<CreateSpendRequestProps> = ({
result.status_details?.requires_action?.next_action ?? null,
);
setStatus('requires_action');
} else if (requestApproval) {
} else if (requestApproval && result.status !== 'approved') {
setStatus('waiting');
} else {
setStatus('success');
Expand Down Expand Up @@ -518,7 +520,7 @@ export const CreateSpendRequest: React.FC<CreateSpendRequestProps> = ({
)}
</Box>
)}
<AppDownloadQrCodes />
{!approve && <AppDownloadQrCodes />}
</Box>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/spend-request/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export function createSpendRequestCli(
repository={repository}
params={createParams}
requestApproval={requestApproval}
approve={opts.approve ? true : undefined}
outputFile={outputFile}
force={forceOverwrite}
onComplete={(result) => {
Expand Down
Loading