Skip to content

Commit 2d1ce73

Browse files
committed
test(ui): Add checkout credit test
1 parent f258cdb commit 2d1ce73

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

packages/ui/src/components/Checkout/__tests__/Checkout.test.tsx

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,107 @@ describe('Checkout', () => {
309309
});
310310
});
311311

312+
it('renders credit details', async () => {
313+
const { wrapper, fixtures } = await createFixtures(f => {
314+
f.withUser({ email_addresses: ['test@clerk.com'] });
315+
f.withBilling();
316+
});
317+
318+
fixtures.clerk.user?.getPaymentMethods.mockResolvedValue({
319+
data: [],
320+
total_count: 0,
321+
});
322+
323+
fixtures.clerk.billing.startCheckout.mockResolvedValue({
324+
id: 'chk_credits_1',
325+
status: 'needs_confirmation',
326+
externalClientSecret: 'cs_test_credits_1',
327+
externalGatewayId: 'gw_test',
328+
totals: {
329+
subtotal: { amount: 2500, amountFormatted: '25.00', currency: 'USD', currencySymbol: '$' },
330+
grandTotal: { amount: 1000, amountFormatted: '10.00', currency: 'USD', currencySymbol: '$' },
331+
taxTotal: { amount: 0, amountFormatted: '0.00', currency: 'USD', currencySymbol: '$' },
332+
credit: { amount: 0, amountFormatted: '0.00', currency: 'USD', currencySymbol: '$' },
333+
credits: {
334+
proration: {
335+
amount: { amount: 500, amountFormatted: '5.00', currency: 'USD', currencySymbol: '$' },
336+
cycleDaysRemaining: 15,
337+
cycleDaysTotal: 30,
338+
cycleRemainingPercent: 50,
339+
},
340+
payer: {
341+
remainingBalance: { amount: 2000, amountFormatted: '20.00', currency: 'USD', currencySymbol: '$' },
342+
appliedAmount: { amount: 1000, amountFormatted: '10.00', currency: 'USD', currencySymbol: '$' },
343+
},
344+
total: { amount: 1500, amountFormatted: '15.00', currency: 'USD', currencySymbol: '$' },
345+
},
346+
pastDue: { amount: 0, amountFormatted: '0.00', currency: 'USD', currencySymbol: '$' },
347+
totalDueNow: { amount: 1000, amountFormatted: '10.00', currency: 'USD', currencySymbol: '$' },
348+
},
349+
isImmediatePlanChange: true,
350+
planPeriod: 'month',
351+
plan: {
352+
id: 'plan_credits',
353+
name: 'Pro',
354+
description: 'Pro plan',
355+
features: [],
356+
fee: {
357+
amount: 2500,
358+
amountFormatted: '25.00',
359+
currency: 'USD',
360+
currencySymbol: '$',
361+
},
362+
annualFee: {
363+
amount: 30000,
364+
amountFormatted: '300.00',
365+
currency: 'USD',
366+
currencySymbol: '$',
367+
},
368+
annualMonthlyFee: {
369+
amount: 2500,
370+
amountFormatted: '25.00',
371+
currency: 'USD',
372+
currencySymbol: '$',
373+
},
374+
slug: 'pro',
375+
avatarUrl: '',
376+
publiclyVisible: true,
377+
isDefault: true,
378+
isRecurring: true,
379+
hasBaseFee: false,
380+
forPayerType: 'user',
381+
freeTrialDays: 7,
382+
freeTrialEnabled: true,
383+
},
384+
paymentMethod: undefined,
385+
confirm: vi.fn(),
386+
freeTrialEndsAt: null,
387+
needsPaymentMethod: false,
388+
} as any);
389+
390+
const { getByRole, getByText } = render(
391+
<Drawer.Root
392+
open
393+
onOpenChange={() => {}}
394+
>
395+
<Checkout
396+
planId='plan_credits'
397+
planPeriod='month'
398+
/>
399+
</Drawer.Root>,
400+
{ wrapper },
401+
);
402+
403+
await waitFor(() => {
404+
expect(getByRole('heading', { name: 'Checkout' })).toBeVisible();
405+
});
406+
407+
expect(getByText('Credit for the remainder of your current subscription.')).toBeVisible();
408+
expect(getByText('Credit from account balance.')).toBeVisible();
409+
expect(getByText('- $5.00')).toBeVisible();
410+
expect(getByText('- $10.00')).toBeVisible();
411+
});
412+
312413
it('renders free trial details during confirmation stage', async () => {
313414
const { wrapper, fixtures } = await createFixtures(f => {
314415
f.withUser({ email_addresses: ['test@clerk.com'] });

0 commit comments

Comments
 (0)