import { randomBytes } from 'node:crypto'; import { mkdtempSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { Temporal } from '@js-temporal/polyfill'; import { afterEach, describe, expect, it } from 'vitest'; import { switchSignup } from '../src/admin/store.js'; import { createApp } from '../src/app.js'; import { issueCancelToken, issuePartyToken } from '../src/cancel-token.js'; import { cancelSignup, changePartySize } from '../src/signup.js'; import { loadConfig } from '../src/config.js'; import { openAppDatabase } from '../src/db.js'; import { issueFormToken } from '../src/form-token.js'; import { MANAGE_TOKEN_LIMIT } from '../src/rate-limit.js'; import { devEnv } from './env.js'; const NOW = '2026-10-14T18:00:00.000Z'; const NOW_MS = Temporal.Instant.from(NOW).epochMilliseconds; const SECRET = 'dev-only-change-me-not-for-production-use'; 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('manage-link cancellation', () => { it('cancels one signup, frees the spot, and does not send mail', async () => { const { app, db, shiftId } = await buildApp({ capacity: 1 }); const { managePath, token } = await openManage(app, shiftId, 'pat.cancel@example.invalid', '203.0.113.70'); const before = db.prepare('SELECT status, created_at, updated_at FROM signups').get() as { status: string; created_at: string; updated_at: string; }; const viewed = await app.request(managePath); expect(viewed.status).toBe(200); const viewedHtml = await viewed.text(); expect(viewedHtml).toContain('Cancel this signup'); expect(viewedHtml).toContain('>Cancel<'); expect(viewedHtml).toContain('>9:00 AM to '); expect(viewedHtml).not.toContain('queues a change email'); expect(db.prepare('SELECT status, updated_at FROM signups').get()).toEqual({ status: 'confirmed', updated_at: before.updated_at, }); expect(before.created_at).toBe(before.updated_at); const full = await app.request(`/s/${shiftId}`); expect(await full.text()).toContain('1 of 1 spots filled'); const cancelled = await postCancel(app, managePath, token); expect(cancelled.status).toBe(303); expect(cancelled.headers.get('location')).toBe(managePath); const page = await app.request(managePath); const html = await page.text(); expect(page.status).toBe(200); expect(html).toContain('Cancelled'); expect(html).toContain('This signup is cancelled'); expect(html).toContain('Pat Cancel'); expect(html).not.toContain('