dev1/tests/e2e/33-billing-portal-flow.spec.mjs

37 lines
1.6 KiB
JavaScript

// @ts-check
import { test, expect } from '@playwright/test';
import { loadTestUser } from '../utils/testUser.js';
test.describe('@p0 Billing portal — return_url flow', () => {
test.setTimeout(20000);
test('Manage subscription → redirects to return_url and cleans ?portal=done', async ({ page }) => {
const u = loadTestUser();
// Stub portal endpoint to return a same-origin URL we can follow safely
await page.route('**/api/premium/stripe/customer-portal**', async (route) => {
const url = `${new URL(route.request().url()).origin}/profile?portal=done`;
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ url }) });
});
// Sign in and open Profile
await page.context().clearCookies();
await page.goto('/signin', { waitUntil: 'networkidle' });
await page.getByPlaceholder('Username', { exact: true }).fill(u.username);
await page.getByPlaceholder('Password', { exact: true }).fill(u.password);
await page.getByRole('button', { name: /^Sign In$/ }).click();
await page.waitForURL('**/signin-landing**', { timeout: 15000 });
await page.goto('/profile', { waitUntil: 'networkidle' });
// Click "Manage subscription" → we should "navigate" to /profile?portal=done
await page.getByRole('button', { name: /^Manage subscription$/i }).click();
await expect(page).toHaveURL(/\/profile\?portal=done$/i, { timeout: 8000 });
// Your effect should refresh status and then clean the param
await expect
.poll(() => page.url(), { timeout: 8000 })
.not.toMatch(/portal=done/i);
});
});