55 lines
2.4 KiB
JavaScript
55 lines
2.4 KiB
JavaScript
// tests/e2e/43-billing-paywall.spec.mjs
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('Billing / Paywall', () => {
|
|
test('Logged-out: falls back to pricing, anchors render, Back works', async ({ page }) => {
|
|
// Ensure logged-out and create history so Back is deterministic
|
|
await page.goto('/signin'); // public page
|
|
await page.goto('/billing'); // paywall
|
|
|
|
await expect(page.getByText('Loading…')).toBeVisible();
|
|
|
|
await expect(page.getByRole('heading', { name: 'Upgrade to AptivaAI' })).toBeVisible();
|
|
await expect(page.getByRole('heading', { name: 'Premium' })).toBeVisible();
|
|
await expect(page.getByRole('heading', { name: 'Pro Premium' })).toBeVisible();
|
|
|
|
await expect(page.getByRole('button', { name: /\$4\.99/ })).toBeVisible();
|
|
await expect(page.getByRole('button', { name: /\$49/ })).toBeVisible();
|
|
await expect(page.getByRole('button', { name: /\$7\.99/ })).toBeVisible();
|
|
await expect(page.getByRole('button', { name: /\$79/ })).toBeVisible();
|
|
|
|
// Back button returns to previous page (signin)
|
|
await page.getByRole('button', { name: /Cancel \/ Go back/i }).click();
|
|
await expect(page).toHaveURL(/\/signin/);
|
|
});
|
|
|
|
test('Logged-out: clicking price posts correct checkout payload; no redirect on non-OK', async ({ page }) => {
|
|
// Stay logged-out so the checkout POST is expected to be non-OK (no redirect)
|
|
await page.goto('/billing');
|
|
|
|
const scenarios = [
|
|
{ re: /\$4\.99/, tier: 'premium', cycle: 'monthly' },
|
|
{ re: /\$49/, tier: 'premium', cycle: 'annual' },
|
|
{ re: /\$7\.99/, tier: 'pro', cycle: 'monthly' },
|
|
{ re: /\$79/, tier: 'pro', cycle: 'annual' },
|
|
];
|
|
|
|
for (const s of scenarios) {
|
|
const [req] = await Promise.all([
|
|
page.waitForRequest(r =>
|
|
r.url().endsWith('/api/premium/stripe/create-checkout-session') && r.method() === 'POST'
|
|
),
|
|
page.getByRole('button', { name: s.re }).click(),
|
|
]);
|
|
const body = JSON.parse(req.postData() || '{}');
|
|
expect(body.tier).toBe(s.tier);
|
|
expect(body.cycle).toBe(s.cycle);
|
|
expect(body.success_url).toMatch(/\/billing\?ck=success$/);
|
|
expect(body.cancel_url).toMatch(/\/billing\?ck=cancel$/);
|
|
|
|
// Should remain on /billing because response is non-OK when logged-out
|
|
await expect(page).toHaveURL(/\/billing$/);
|
|
}
|
|
});
|
|
});
|