fix(m2-m3): data-testid on new-client+add-client btns; fix client subscriptions API response shape; update E2E specs

This commit is contained in:
root
2026-03-26 09:15:25 +00:00
parent ce179ac799
commit 50fd7e39fc
6 changed files with 115 additions and 53 deletions

View File

@@ -9,15 +9,43 @@ export const DEMO = {
// Use the public API URL — Node.js requests bypass browser CORS
const API_URL = 'https://fiberops-api.juankibin.space';
// Cache token across tests to avoid rate-limiting
let cachedAuth: { accessToken: string; user: any; expiresAt: number } | null = null;
export async function loginViaAPI(creds = DEMO) {
const ctx = await playwrightRequest.newContext({ baseURL: API_URL });
const resp = await ctx.post('/api/v1/auth/login', {
data: { tenantSlug: creds.tenant, email: creds.email, password: creds.password },
headers: { 'Content-Type': 'application/json', 'x-tenant-slug': creds.tenant },
});
const data = await resp.json();
await ctx.dispose();
return data; // { accessToken, refreshToken, user }
// Return cached token if still fresh (within 4 minutes)
if (cachedAuth && Date.now() < cachedAuth.expiresAt) {
return { accessToken: cachedAuth.accessToken, user: cachedAuth.user };
}
// Retry up to 3 times with backoff
for (let attempt = 0; attempt < 3; attempt++) {
const ctx = await playwrightRequest.newContext({ baseURL: API_URL });
try {
const resp = await ctx.post('/api/v1/auth/login', {
data: { tenantSlug: creds.tenant, email: creds.email, password: creds.password },
headers: { 'Content-Type': 'application/json', 'x-tenant-slug': creds.tenant },
});
const data = await resp.json();
if (data.accessToken) {
// Cache for 4 minutes
cachedAuth = {
accessToken: data.accessToken,
user: data.user,
expiresAt: Date.now() + 4 * 60 * 1000,
};
return data;
}
console.warn(`Login attempt ${attempt + 1} returned no token:`, JSON.stringify(data).slice(0, 200));
} catch (err) {
console.warn(`Login attempt ${attempt + 1} failed:`, err);
} finally {
await ctx.dispose();
}
// Backoff
if (attempt < 2) await new Promise(r => setTimeout(r, 1000 * (attempt + 1)));
}
throw new Error('loginViaAPI: Failed to obtain token after 3 attempts');
}
export async function login(page: Page, creds = DEMO) {
@@ -40,4 +68,7 @@ export async function login(page: Page, creds = DEMO) {
// Step 3: Navigate to dashboard — auth guard reads localStorage and passes
await page.goto('/dashboard');
await page.waitForURL(/\/(dashboard|clients|settings)/, { timeout: 15000 });
// Step 4: Verify we're actually on the dashboard (not redirected to login)
await page.waitForSelector('h1:has-text("Dashboard")', { timeout: 10000 });
}