diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-18 23:08:46 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-18 23:08:46 +0300 |
| commit | a9b75513661cb9196cb6bd614f56c4bf09c970b5 (patch) | |
| tree | fc4fb08d1549d4f9e04ea5c5398298d22e68f40a | |
| parent | 687837c4633ff5567618a9042a06ccc77d5e178f (diff) | |
Fix Playwright race condition in admin-gate test
The admin check test registered waitForResponse after page.goto(), so the
403 from API.users() (fired at SPA init) could arrive before the listener
was active — causing a 10 s timeout. Fix: inject the session cookie and
register the response listener before navigation, then await the promise
after goto(). Also corrects the URL filter: the SPA calls /api/admin/users
(not /api/v1/admin/users) so the pattern now matches the actual request.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rw-r--r-- | player-server/test/e2e-web/tests/smoke.test.ts | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/player-server/test/e2e-web/tests/smoke.test.ts b/player-server/test/e2e-web/tests/smoke.test.ts index 50a4ef2..d998b86 100644 --- a/player-server/test/e2e-web/tests/smoke.test.ts +++ b/player-server/test/e2e-web/tests/smoke.test.ts @@ -358,17 +358,19 @@ test('admin gear button is visible and opens admin panel for admin user', async test('admin panel is not accessible to regular user', async ({ page }) => { const cookie = await login(REGULAR_USER, REGULAR_PASS); - await openAuthenticatedPage(page, cookie, '/'); - await waitForAppReady(page); - // For a non-admin the admin toggle stays hidden because API.users() returns - // 403, so showAdmin() is never called. Wait for the 403 response to arrive - // before checking the DOM — this avoids a fixed sleep and surfaces failures - // cleanly if the request never fires. - await page.waitForResponse( - resp => resp.url().includes('/api/v1/admin/users') && resp.status() === 403, + // Register the response listener BEFORE navigating so it cannot miss the + // API.users() call that fires at SPA init. waitForResponse only catches + // future responses — setting it up after goto() creates a race condition + // where the 403 may already be received by the time the listener is active. + await injectSessionCookie(page.context(), cookie); + const adminCheck = page.waitForResponse( + resp => resp.url().includes('/api/admin/users') && resp.status() === 403, { timeout: 10_000 }, ); + await page.goto('/'); + await adminCheck; + const adminToggle = page.locator('#admin-toggle'); const classes = (await adminToggle.getAttribute('class')) ?? ''; expect(classes).toContain('hidden'); |
