dev1/tests/e2e/42-billing-refresh-status.spec.mjs

54 lines
2.0 KiB
JavaScript

// @ts-check
import { test, expect } from '@playwright/test';
import { loadTestUser } from '../utils/testUser.js';
test.describe('@p0 Billing — Refresh status updates plan label', () => {
test.setTimeout(20000);
test('Refresh status re-reads and updates plan label', async ({ page }) => {
const u = loadTestUser();
// First response: Free; second response: Premium
let calls = 0;
await page.route('**/api/premium/subscription/status', async (route) => {
calls += 1;
if (calls === 1) {
return route.fulfill({
status: 200, contentType: 'application/json',
body: JSON.stringify({ is_premium: 0, is_pro_premium: 0 })
});
}
return route.fulfill({
status: 200, contentType: 'application/json',
body: JSON.stringify({ is_premium: 1, is_pro_premium: 0 })
});
});
// Sign in → 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' });
// Initial plan label should mention Free
const planLine = page.getByText(/^Current plan:/i);
await expect(planLine).toBeVisible({ timeout: 5000 });
const initialText = (await planLine.textContent() || '').toLowerCase();
expect(initialText.includes('free')).toBeTruthy();
// Click Refresh status → label should update to Premium
await page.getByRole('button', { name: /^Refresh status$/i }).click();
await expect
.poll(async () => {
const txt = (await planLine.textContent() || '').toLowerCase();
return txt.includes('premium');
}, { timeout: 8000 })
.toBeTruthy();
});
});