import { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import { listMoveTargets, switchSignup } from '../src/admin/store.js';
import { createApp, publicDirectory } from '../src/app.js';
import { loadConfig } from '../src/config.js';
import { openAppDatabase } from '../src/db.js';
import { Hono } from 'hono';
import { CONTENT_SECURITY_POLICY, PERMISSIONS_POLICY, securityHeaders, STRICT_TRANSPORT_SECURITY } from '../src/security.js';
import { reserveSignup } from '../src/signup.js';
import { localShiftToUtc } from '../src/time.js';
import { devEnv } from './env.js';
const NOW = '2026-10-14T18:00:00.000Z';
const dirs: string[] = [];
const databases: { close: () => void }[] = [];
afterEach(() => {
for (const database of databases.splice(0)) database.close();
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
});
describe('public pages', () => {
it('lists upcoming published shifts and hides private details', async () => {
const { app, ids } = await buildApp();
const home = await app.request('/');
expect(home.status).toBe(200);
const html = await home.text();
expect(html).toContain('Weekly pantry');
expect(html).not.toContain('Upcoming shifts');
expect(html).toContain('>Sign Up');
expect(html).toContain('>List');
expect(html).toContain('href="/?view=calendar">Calendar');
expect(html).toContain('Sign-up is open through January 14, 2027.');
expect(html).toContain('Wednesday Sorting');
expect(html).toContain('Wednesday Greeting');
expect(html).toContain('Lane Wednesday');
expect(html).toContain('Thursday');
expect(html).toContain('class="day-card-dow">Friday');
expect(html).toContain('Open Sorting');
expect(html).toContain('Full Intake');
expect(html).toContain('Today');
expect(html).toContain('aria-current="date"');
expect(html).toContain('In progress');
expect(html).not.toContain('Volunteer tools');
const header = html.slice(html.indexOf('class="header"'), html.indexOf('Volunteering');
expect(header).toContain('href="https://hopefoodpantrysc.org/"');
expect(header).toContain('href="https://hopefoodpantrysc.org/about"');
expect(header).toContain('href="https://hopefoodpantrysc.org/faq"');
expect(header).toContain('href="https://hopefoodpantrysc.org/#contact"');
expect(header).toContain('https://donorbox.org/hope-food-pantry-1');
expect(header).not.toContain('Coordinator');
expect(header).not.toContain('>Privacy');
expect(header).not.toContain('Calendar');
expect(header).not.toContain('Log out');
const nav = html.slice(html.indexOf('class="nav-links"'), html.indexOf(''));
expect(nav).toContain('Donate');
expect(nav).not.toContain('Coordinator');
expect(nav).not.toContain('Privacy');
expect(nav).not.toContain('Log out');
const footer = html.slice(html.indexOf('class="footer"'));
expect(footer).toContain('equal opportunity provider');
expect(footer).toContain('Cosmically Creative');
expect(footer).toContain('712\u2011540\u20119351');
expect(footer).toContain('class="main-nav-link" href="/" aria-current="page">Volunteering');
expect(footer).not.toContain('Privacy');
expect(footer).not.toContain('Coordinator');
expect(html).not.toContain('Cancelled Distribution');
expect(html).toContain('Past Setup');
expect(html).not.toContain(`href="/s/${ids.past}"`);
expect(html).not.toContain('Hidden draft');
expect(html).toContain('Secret Person');
expect(html).not.toContain('secret.person@example.invalid');
expect(html).not.toContain('lane.wednesday@example.invalid');
expect(html).not.toContain('SECRET-PERSON-NOTE');
expect(html).not.toContain('SECRET-SHIFT-NOTE');
expect(html).not.toContain('