import { test, expect, type Page } from '@playwright/test'; const adminUrl = process.env.CONVIVO_ADMIN_URL || 'http://localhost:3001'; const source = 'https://sessionize.com/api/v2/z0s5f2j2/view/GridSmart'; async function openEvent(page: Page) { const user = { id: '99999999-9999-4999-8999-999999999999', email: 'admin@appe.at', aud: 'authenticated', role: 'authenticated', app_metadata: {}, user_metadata: {} }; const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url'); const session = { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test`, refresh_token: 'mock-refresh-token', expires_in: 3600, token_type: 'bearer' }; const event = { id: 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa', name: 'Grid Conference', is_active: true, start_date: '2026-10-23', end_date: '2026-10-23', sessionize_endpoint: null, num_registrations: 4, num_sessions: 21, num_speakers: 4 }; const writes: Record[] = []; await page.route('**/auth/v1/**', route => route.fulfill({ json: new URL(route.request().url()).pathname.endsWith('/user') ? user : session })); await page.route('**/rest/v1/**', async route => { const url = new URL(route.request().url()); const path = url.pathname; if (path.endsWith('/events')) { if (route.request().method() === 'PATCH') { writes.push(route.request().postDataJSON()); return route.fulfill({ status: 204 }); } return route.fulfill({ json: url.searchParams.has('is_active') ? event : [event] }); } if (path.endsWith('/contacts')) { const contact = { email: user.email, full_name: 'Admin', is_admin: true }; return route.fulfill({ json: url.searchParams.has('email') ? contact : [contact] }); } return route.fulfill({ json: [] }); }); await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`); await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toBeVisible(); await page.locator('.nav').getByRole('button', { name: /Events/ }).click(); await page.getByRole('button', { name: 'Edit', exact: true }).click(); return writes; } for (const [format, value] of [['URL', source], ['script', ``]]) { test(`saves ${format} as a normalized Sessionize source`, async ({ page }, testInfo) => { await page.setViewportSize({ width: 1280, height: 900 }); const writes = await openEvent(page); await page.getByLabel('Sessionize endpoint').fill(value); await page.screenshot({ path: testInfo.outputPath(`sessionize-${format}.png`), fullPage: true }); await page.getByRole('button', { name: 'Save', exact: true }).click(); await expect.poll(() => writes.length).toBe(1); expect(writes[0].sessionize_endpoint).toBe(source); }); } test('rejects invalid source without saving or executing pasted scripts', async ({ page }) => { const writes = await openEvent(page); await page.getByLabel('Sessionize endpoint').fill(''); await page.getByRole('button', { name: 'Save', exact: true }).click(); await expect(page.getByRole('alert')).toHaveText('Use a Sessionize HTTPS All or GridSmart endpoint'); expect(writes).toHaveLength(0); expect(await page.evaluate(() => 'testExecuted' in window)).toBe(false); await expect(page.getByLabel('Sessionize endpoint')).toBeVisible(); });