35 lines
1.5 KiB
JavaScript
35 lines
1.5 KiB
JavaScript
// @ts-check
|
|
import { test, expect } from '@playwright/test';
|
|
import { loadTestUser } from '../utils/testUser.js';
|
|
|
|
test.describe('@premium Premium → refresh to free locks routes', () => {
|
|
test.setTimeout(50000);
|
|
|
|
test('refresh status to free redirects to /paywall on premium routes', async ({ page }) => {
|
|
const u = loadTestUser();
|
|
let calls = 0;
|
|
await page.route('**/api/premium/subscription/status', async route => {
|
|
calls += 1;
|
|
const body = calls === 1
|
|
? { is_premium: 1, is_pro_premium: 0 } // first load premium
|
|
: { is_premium: 0, is_pro_premium: 0 }; // after refresh → free
|
|
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(body) });
|
|
});
|
|
|
|
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 });
|
|
|
|
// Profile → Refresh status (flips to free)
|
|
await page.goto('/profile', { waitUntil: 'networkidle' });
|
|
await page.getByRole('button', { name: /^Refresh status$/i }).click();
|
|
|
|
// Try premium route → now should hit paywall
|
|
await page.goto('/enhancing', { waitUntil: 'networkidle' });
|
|
await expect(page).toHaveURL(/\/paywall/i);
|
|
});
|
|
});
|