# Instructions

- Following Playwright test failed.
- Explain why, be concise, respect Playwright best practices.
- Provide a snippet of code with the fix, if possible.

# Test info

- Name: tests/ui/auth.spec.ts >> sign-in and premium sections >> /voters/ answers 200 for the test identity
- Location: tests/ui/auth.spec.ts:70:9

# Error details

```
Test timeout of 30000ms exceeded.
```

```
Error: apiRequestContext.get: Request context disposed.
Call log:
  - → GET http://10.1.105.75/auth/whoami
    - user-agent: Playwright/1.64.1 (x64; ubuntu 22.04) node/20.9 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br

```

# Test source

```ts
  1   | import { test, expect } from '@playwright/test';
  2   | 
  3   | // Sign-in and premium sections (electinfo/sites#270). /auth/whoami reports
  4   | // whether Authentik is on for the host under test:
  5   | //   - CI test pods: enabled "false" (no Traefik in front), so nothing is gated
  6   | //     and the homepage keeps its premium cards greyed out;
  7   | //   - preview.elect.info front door: enabled "true", signed in as the
  8   | //     preview-e2e service account (preview-e2e@elect.info, so elevated).
  9   | const PREMIUM = [
  10  |   { path: '/voters/', label: 'Voters' },
  11  |   { path: '/individuals/', label: 'Individual Donors' },
  12  |   { path: '/blocks/', label: 'Census Blocks' },
  13  | ];
  14  | 
  15  | interface WhoAmI {
  16  |   enabled: string;
  17  |   email: string;
  18  |   elevated: boolean;
  19  |   entitlements: { voters: boolean; individuals: boolean; blocks: boolean; curator: boolean };
  20  | }
  21  | 
  22  | async function whoami(request: import('@playwright/test').APIRequestContext): Promise<WhoAmI> {
> 23  |   const res = await request.get('/auth/whoami', { maxRedirects: 0 });
      |                             ^ Error: apiRequestContext.get: Request context disposed.
  24  |   expect(res.status(), '/auth/whoami answers 200').toBe(200);
  25  |   expect(res.headers()['cache-control']).toContain('no-store');
  26  |   return (await res.json()) as WhoAmI;
  27  | }
  28  | 
  29  | test.describe('sign-in and premium sections', () => {
  30  |   test('/auth/whoami returns well-formed JSON', async ({ request }) => {
  31  |     const me = await whoami(request);
  32  |     expect(['true', 'false']).toContain(me.enabled);
  33  |     expect(typeof me.email).toBe('string');
  34  |     expect(typeof me.elevated).toBe('boolean');
  35  |     // Per-section entitlements (sites#305), always all four booleans.
  36  |     expect(Object.keys(me.entitlements).sort()).toEqual(['blocks', 'curator', 'individuals', 'voters']);
  37  |     for (const v of Object.values(me.entitlements)) expect(typeof v).toBe('boolean');
  38  |     expect(me.elevated).toBe(me.entitlements.voters || me.entitlements.individuals || me.entitlements.blocks);
  39  |     if (me.enabled === 'false') {
  40  |       expect(me.email).toBe('');
  41  |       expect(me.elevated).toBe(false);
  42  |       expect(Object.values(me.entitlements).some(Boolean)).toBe(false);
  43  |     }
  44  |   });
  45  | 
  46  |   test('a forged identity header grants nothing where Authentik is off', async ({ request }) => {
  47  |     const res = await request.get('/auth/whoami', {
  48  |       headers: { 'X-authentik-email': 'someone@elect.info' },
  49  |     });
  50  |     const me = (await res.json()) as WhoAmI;
  51  |     test.skip(me.enabled === 'true', 'host has Authentik: Traefik sets the header');
  52  |     expect(me.email).toBe('');
  53  |     expect(me.elevated).toBe(false);
  54  |   });
  55  | 
  56  |   for (const group of ['elect-info-premium', 'ei-voter-viewers', 'ei-donor-viewers', 'ei-block-viewers', 'elect-news-curators']) {
  57  |     test(`a forged ${group} group header grants nothing where Authentik is off`, async ({ request }) => {
  58  |       const res = await request.get('/auth/whoami', {
  59  |         headers: { 'X-authentik-email': 'someone@example.com', 'X-authentik-groups': group },
  60  |       });
  61  |       const me = (await res.json()) as WhoAmI;
  62  |       test.skip(me.enabled === 'true', 'host has Authentik: Traefik sets the headers');
  63  |       expect(me.email).toBe('');
  64  |       expect(me.elevated).toBe(false);
  65  |       expect(Object.values(me.entitlements).some(Boolean)).toBe(false);
  66  |     });
  67  |   }
  68  | 
  69  |   for (const { path } of PREMIUM) {
  70  |     test(`${path} answers 200 for the test identity`, async ({ page, request }) => {
  71  |       const me = await whoami(request);
  72  |       test.skip(me.enabled === 'true' && !me.elevated, 'signed in without elevated access');
  73  |       const response = await page.goto(path);
  74  |       expect(response?.status()).toBe(200);
  75  |     });
  76  |   }
  77  | 
  78  |   // The placeholder became the voter search page (sites#277, tests/voters.spec.ts).
  79  |   test('/voters/ is the voter search page', async ({ page }) => {
  80  |     await page.goto('/voters/');
  81  |     await expect(page.locator('h1')).toHaveText('Voters');
  82  |     await expect(page.locator('script[src="/js/voter-index.js"]')).toHaveCount(1);
  83  |     await expect(page.locator('.coming-soon')).toHaveCount(0);
  84  |   });
  85  | 
  86  |   test('the premium notice page is not directly reachable', async ({ page }) => {
  87  |     const response = await page.goto('/premium-required.html');
  88  |     expect(response?.status()).toBe(404);
  89  |   });
  90  | 
  91  |   test('homepage premium cards follow the account', async ({ page, request }) => {
  92  |     const me = await whoami(request);
  93  |     await page.goto('/');
  94  |     for (const { path, label } of PREMIUM) {
  95  |       const card = page.locator(`[data-premium-href="${path}"]`);
  96  |       await expect(card).toHaveCount(1);
  97  |       await expect(card).toContainText(label);
  98  |       const area = path.replace(/\//g, '') as 'voters' | 'individuals' | 'blocks';
  99  |       if (me.enabled === 'true' && me.entitlements[area]) {
  100 |         await expect(page.locator(`a[data-premium-href="${path}"]`)).toHaveAttribute('href', path);
  101 |         await expect(card).not.toHaveClass(/entity-card--disabled/);
  102 |       } else {
  103 |         await expect(card).toHaveClass(/entity-card--disabled/);
  104 |         await expect(page.locator(`a[data-premium-href="${path}"]`)).toHaveCount(0);
  105 |       }
  106 |     }
  107 |   });
  108 | 
  109 |   test('account slot shows the signed-in email where Authentik is on', async ({ page, request }) => {
  110 |     const me = await whoami(request);
  111 |     await page.goto('/');
  112 |     const slot = page.locator('#auth-slot');
  113 |     if (me.enabled !== 'true') {
  114 |       await expect(slot).toBeEmpty();
  115 |       return;
  116 |     }
  117 |     if (me.email) {
  118 |       await expect(slot.locator('.auth-email')).toHaveText(me.email);
  119 |       await expect(slot.locator('a.auth-link', { hasText: 'Log out' })).toHaveAttribute('href', '/outpost.goauthentik.io/sign_out');
  120 |       await expect(slot.locator('.ei-chip').first()).toHaveText('Registered');
  121 |     } else {
  122 |       await expect(slot.locator('a.auth-link')).toHaveText('Log in');
  123 |     }
```