/**
 * USER_JOURNEYS.md §15 — leaving an event clears auth and routes to /join.
 * The journey doc spells out: clears JWT and PIN, calls DELETE /session.
 */
import { test, expect } from '../../fixtures/test';
import { AccountPage } from '../../page-objects';
import { readStorage } from '../../helpers/storage-helpers';

test.describe('Auth — leave event', () => {
  test('leave event clears localStorage and redirects to /join', async ({
    page,
    guest,
    signIn,
  }) => {
    const h = await guest('Jens');
    await signIn(page, h);

    const account = new AccountPage(page);
    await account.goto();
    await account.leaveEvent();

    await expect(page).toHaveURL(/\/join$/);

    const storage = await readStorage(page);
    expect(storage.jwt, 'JWT should be cleared').toBeNull();
    // PIN is intentionally retained per auth.ts so the user can recover.
    expect(storage.userId).toBeNull();
  });
});
