const assert = require('node:assert/strict'); const { chromium } = require(process.env.PLAYWRIGHT_PACKAGE || 'playwright'); const base = process.env.REVIEW_BASE || 'http://localhost:3114'; (async () => { const browser = await chromium.launch(); try { const context = await browser.newContext(); await context.addCookies([{ name: 'magent_logged_in', value: '1', url: base }]); const writes = [], errors = []; await context.route('**/api/**', async route => { const path = new URL(route.request().url()).pathname; const media = { title: "Pan's Labyrinth", type: 'movie', tmdbId: 1417, year: 2006, seasons: [], originalLanguage: { code: 'es' } }; if (path === '/api/auth/me') return route.fulfill({ json: { username: 'Admin', role: 'admin' } }); if (path.startsWith('/api/operations/')) return route.fulfill({ json: { status: 'complete', events: [] } }); if (path === '/api/requests/search') return route.fulfill({ json: { results: [media] } }); if (path === '/api/requests/request-options') return route.fulfill({ json: { media, destination: { collector: 'Radarr', serverName: 'Movies', defaultProfileId: 6, profiles: [] } } }); if (path === '/api/requests/create') { writes.push(route.request().postDataJSON()); return route.fulfill({ json: { requestId: 12 } }); } return route.fulfill({ json: {} }); }); const page = await context.newPage(); page.on('pageerror', e => errors.push(e.message)); for (const width of [1440, 390]) { await page.setViewportSize({ width, height: 900 }); await page.goto(base + '/new-requests'); await page.getByRole('button', { name: /Film.*Movie/ }).click(); await page.getByLabel('Title', { exact: true }).fill('Pans Labyrinth'); await page.getByRole('button', { name: 'Search Seerr' }).click(); await page.getByRole('button', { name: /Pan's Labyrinth/ }).click(); await page.getByRole('heading', { name: 'Check the audio language' }).waitFor(); assert(await page.locator('.request-language-notice').getByText('Spanish', { exact: true }).isVisible()); const consent = page.getByRole('checkbox'); assert(!await consent.isChecked()); await consent.check(); await page.getByRole('button', { name: 'Change title', exact: true }).click(); await page.getByRole('button', { name: /Pan's Labyrinth/ }).click(); await page.getByRole('heading', { name: 'Check the audio language' }).waitFor(); assert(!await consent.isChecked(), 'Consent resets when changing titles'); await consent.check(); assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)); await page.getByRole('button', { name: 'Request movie', exact: true }).click(); await page.getByText('Request #12 has been accepted by Seerr.', { exact: true }).waitFor(); } assert.equal(writes.length, 2); assert(writes.every(w => w.acceptOriginalLanguage === true && w.tmdbId === 1417 && !w.profileId)); assert.deepEqual(errors, []); console.log('Passed: desktop/mobile warning, Spanish metadata, explicit consent, reset on title change and request payload. All APIs intercepted.'); } finally { await browser.close(); } })().catch(e => { console.error(e); process.exitCode = 1; });