feat: open the next three months of Wednesday shifts on the public list

Volunteers can see who is signed up, and a full shift stays closed. Coordinators can see a contact's current and past shifts.
This commit is contained in:
blake committed 2026-10-26 15:45:32 -05:00
1 parent e7c99a788e
commit 1a8959c86a
26 files changed
+1402 -192

No files matched your search

+3 -2
View File
@@ -630,10 +630,11 @@ describe('coordinator screens', () => {
expect(sourceRoster).not.toContain(`/admin/signups/${signupId}/move`);
expect(sourceRoster).toContain('0/2 spots filled');
expect(sourceRoster).toContain('event-pill is-open');
const home = await (await app.request('/')).text();
const home = await (await app.request('/e/pantry?view=calendar')).text();
const shiftPage = await (await app.request(`/s/${destinationId}`)).text();
expect(home).not.toContain('kim@example.invalid');
expect(home).not.toContain('Kim Example');
expect(home).not.toContain('Blue shirt');
expect(home).toContain('Kim Example');
expect(shiftPage).not.toContain('kim@example.invalid');
expect(shiftPage).not.toContain('Attended.');
expect(auditJson(db)).not.toContain('@');
+5 -3
View File
@@ -82,7 +82,9 @@ describe('manage-link cancellation', () => {
{ status: 'confirmed' },
]);
expect((await (await app.request(`/s/${shiftId}`)).text())).toContain('1/1 spots filled');
expect((await (await app.request('/')).text())).not.toContain('Pat Cancel');
const listed = await (await app.request('/?view=calendar')).text();
expect(listed).toContain('Pat Cancel');
expect(listed).not.toContain('pat.cancel@example.invalid');
});
it('refuses a cancel that did not come from this signup page', async () => {
@@ -207,9 +209,9 @@ describe('manage-link switch', () => {
expect(letter.body_text).toContain('You switched this signup to a different shift.');
expect(letter.body_text).not.toContain('A coordinator moved');
expect(letter.body_text).toContain(nextPath.split('?')[0]);
const home = await (await app.request('/')).text();
const home = await (await app.request('/?view=calendar')).text();
expect(home).not.toContain('pat.switch@example.invalid');
expect(home).not.toContain('Pat Cancel');
expect(home).toContain('Pat Cancel');
expect(home).toContain('0/2 spots filled');
expect(home).toContain('1/2 spots filled');
+141 -3
View File
@@ -284,6 +284,120 @@ describe('contact pages', () => {
expect(await hidden.text()).not.toContain('kristi@example.invalid');
});
it('shows current and past shifts on the contact page', async () => {
const { app, db } = await buildApp();
const cookie = await signIn(app, db);
await postFile(
app,
cookie,
[
'First Name,Last Name,Email,Phone',
'Ada,Example,ada@example.invalid,712-555-0101',
'Ada,Other,ada@example.invalid,712-555-0102',
'Pat,-,pat@example.invalid,712-555-0103',
].join('\n'),
);
const currentId = insertShift(db, { title: 'Weekly pantry', role: 'Sorting', start: '2026-10-14T16:00:00.000Z', end: '2026-10-14T20:00:00.000Z' });
const nextId = insertShift(db, { slug: 'next', title: 'Pantry & <shift>', role: 'Packing' });
const quietId = insertShift(db, {
slug: 'soup',
title: 'Soup kitchen',
role: 'Serving',
published: 0,
start: '2026-10-22T14:00:00.000Z',
end: '2026-10-22T17:00:00.000Z',
});
const greetingId = insertShift(db, {
slug: 'door',
title: 'Front door',
role: 'Greeting',
start: '2026-10-23T14:00:00.000Z',
end: '2026-10-23T17:00:00.000Z',
});
const endedId = insertShift(db, {
slug: 'finished',
title: 'Finished pantry',
role: 'Finished',
start: '2026-10-14T14:00:00.000Z',
end: '2026-10-14T17:00:00.000Z',
});
const olderId = insertShift(db, {
slug: 'older',
title: 'Older pantry',
role: 'Older',
start: '2026-10-07T14:00:00.000Z',
end: '2026-10-07T17:00:00.000Z',
});
const closedId = insertShift(db, { slug: 'closed', title: 'Closed pantry', role: 'Closing', cancelled: 1 });
const droppedId = insertShift(db, {
slug: 'dropped',
title: 'Dropped pantry',
role: 'Dropped',
start: '2026-10-24T14:00:00.000Z',
end: '2026-10-24T17:00:00.000Z',
});
insertSignup(db, currentId, { name: 'ADA EXAMPLE', email: 'ada@example.invalid' });
insertSignup(db, nextId, { name: 'Ada Example', email: 'ada@example.invalid' });
insertSignup(db, quietId, { name: 'Ada Example', email: 'ada@example.invalid' });
insertSignup(db, greetingId, { name: 'Pat', email: 'pat@example.invalid' });
insertSignup(db, endedId, { name: 'Ada Example', email: 'ada@example.invalid' });
insertSignup(db, olderId, { name: 'Ada Example', email: 'ada@example.invalid', status: 'cancelled' });
insertSignup(db, closedId, { name: 'Ada Example', email: 'ada@example.invalid' });
insertSignup(db, droppedId, { name: 'Ada Example', email: 'ada@example.invalid', status: 'cancelled' });
insertSignup(db, greetingId, { name: 'Ada Other', email: 'other@example.invalid' });
const found = await app.request('/admin/contacts?q=ada', { headers: { cookie } });
const foundHtml = await found.text();
expect(foundHtml).toContain('Ada Example');
expect(foundHtml).toContain('Ada Other');
expect(foundHtml).not.toContain('Not signed up for a shift.');
expect(foundHtml).not.toContain('Pantry &amp; &lt;shift&gt;');
expect(foundHtml).not.toContain('/admin/shifts/');
const adaId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = 'Example'`).get() as { id: number }).id;
const person = await app.request(`/admin/contacts/${adaId}`, { headers: { cookie } });
const personHtml = await person.text();
const current = sectionHtml(personHtml, 'Signed up for', 'Past shifts');
const past = sectionHtml(personHtml, 'Past shifts', 'Edit contact');
expect(current).toContain(`href="/admin/shifts/${currentId}"`);
expect(current).toContain('Weekly pantry: Sorting, October 14, 2026, 11:00 AM to 3:00 PM CDT');
expect(current).toContain(`href="/admin/shifts/${nextId}"`);
expect(current).toContain('Pantry &amp; &lt;shift&gt;: Packing, October 21, 2026, 9:00 AM to 12:00 PM CDT');
expect(current).not.toContain('Pantry & <shift>');
expect(current).toContain(`href="/admin/shifts/${quietId}"`);
expect(current).toContain('Soup kitchen: Serving, October 22, 2026, 9:00 AM to 12:00 PM CDT (not on the public list)');
expect(current.indexOf(`href="/admin/shifts/${currentId}"`)).toBeLessThan(current.indexOf(`href="/admin/shifts/${nextId}"`));
expect(current.indexOf(`href="/admin/shifts/${nextId}"`)).toBeLessThan(current.indexOf(`href="/admin/shifts/${quietId}"`));
expect(current).not.toContain('Finished');
expect(current).not.toContain('Closing');
expect(current).not.toContain('Dropped');
expect(past).toContain(`href="/admin/shifts/${endedId}"`);
expect(past).toContain('Finished pantry: Finished, October 14, 2026, 9:00 AM to 12:00 PM CDT');
expect(past).toContain(`href="/admin/shifts/${olderId}"`);
expect(past).toContain('Older pantry: Older, October 7, 2026, 9:00 AM to 12:00 PM CDT (cancelled)');
expect(past.indexOf(`href="/admin/shifts/${endedId}"`)).toBeLessThan(past.indexOf(`href="/admin/shifts/${olderId}"`));
expect(past).not.toContain('Weekly pantry');
expect(past).not.toContain('Dropped');
expect(past).not.toContain('Closing');
expect(personHtml).toContain('<summary>Edit contact');
expect(personHtml).toContain('<summary>Add to a shift');
expect(personHtml.match(/<details class="contact-menu" name="contact-action"/g)).toHaveLength(2);
expect(personHtml).not.toContain('<details class="contact-menu" open');
const otherId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = 'Other'`).get() as { id: number }).id;
const otherPage = await app.request(`/admin/contacts/${otherId}`, { headers: { cookie } });
const otherHtml = await otherPage.text();
expect(otherHtml).toContain('Not signed up for a shift.');
expect(otherHtml).toContain('No past shifts.');
expect(otherHtml).not.toContain('/admin/shifts/');
const patId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = '-'`).get() as { id: number }).id;
const patPage = await app.request(`/admin/contacts/${patId}`, { headers: { cookie } });
const patHtml = await patPage.text();
expect(sectionHtml(patHtml, 'Signed up for', 'Past shifts')).toContain(`href="/admin/shifts/${greetingId}"`);
expect(patHtml).toContain('Front door: Greeting, October 23, 2026, 9:00 AM to 12:00 PM CDT');
});
it('fills a walk-in from a saved contact and can remove the contact afterward', async () => {
const { app, db } = await buildApp();
const cookie = await signIn(app, db);
@@ -475,7 +589,12 @@ describe('contact pages', () => {
expect(loggedOut.status).toBe(303);
const cookie = await signIn(app, db);
const page = await app.request('/admin/contacts', { headers: { cookie } });
expect(await page.text()).toContain('Save this contact');
const pageHtml = await page.text();
expect(pageHtml).toContain('Save this contact');
expect(pageHtml.indexOf('id="contacts-heading"')).toBeGreaterThan(-1);
expect(pageHtml.indexOf('id="contacts-heading"')).toBeLessThan(pageHtml.indexOf('<summary>Add a contact'));
expect(pageHtml.match(/<details class="contact-menu" name="contact-tools"/g)).toHaveLength(3);
expect(pageHtml).not.toContain('<details class="contact-menu" name="contact-tools" open');
const saved = await postManual(app, cookie, { firstName: 'ada', lastName: 'example', email: 'Ada@Example.invalid', phone: '7125550100' });
expect(saved.status).toBe(303);
@@ -521,6 +640,7 @@ describe('contact pages', () => {
expect(invalidHtml).toContain('Enter a first name.');
expect(invalidHtml).toContain('Enter an email address.');
expect(invalidHtml).toContain('Enter a phone number.');
expect(invalidHtml).toContain('<details class="contact-menu" name="contact-tools" open');
expect(count(db, 'SELECT COUNT(*) AS n FROM contacts')).toBe(2);
expect(await (await app.request('/')).text()).not.toContain('ada@example.invalid');
});
@@ -540,8 +660,9 @@ describe('contact pages', () => {
const person = await app.request(`/admin/contacts/${contactId}`, { headers: { cookie } });
const personHtml = await person.text();
expect(person.status).toBe(200);
expect(personHtml).toContain('Correct this contact');
expect(personHtml).toContain('Save this correction');
expect(personHtml).toContain('Edit contact');
expect(personHtml).toContain('Save contact');
expect(personHtml).not.toContain('Correct this contact');
expect(personHtml).toContain('value="Pat"');
expect(personHtml).toContain('value="-"');
expect(personHtml).toContain('value="pat@example.invalid"');
@@ -739,6 +860,23 @@ function rowMarkup(html: string, name: string): string {
return li < 0 || at < 0 ? '' : html.slice(li, at);
}
function sectionHtml(html: string, start: string, end: string): string {
const at = html.indexOf(start);
const stop = html.indexOf(end, at + start.length);
return at < 0 || stop < 0 ? '' : html.slice(at, stop);
}
function insertSignup(
db: Awaited<ReturnType<typeof openDb>>,
shiftId: number,
person: { name: string; email: string; status?: string },
) {
db.prepare(
`INSERT INTO signups (shift_id, name, email, email_norm, group_size, status, created_at, updated_at)
VALUES (?, ?, ?, ?, 1, ?, ?, ?)`,
).run(shiftId, person.name, person.email, person.email, person.status ?? 'confirmed', NOW, NOW);
}
function count(db: Awaited<ReturnType<typeof openDb>>, sql: string): number {
return (db.prepare(sql).get() as { n: number }).n;
}
+10 -10
View File
@@ -32,15 +32,15 @@ describe('daily weekly refill', () => {
const ended = insertEvent(db, 'ended', CHICAGO);
insertTemplate(db, ended, 4, '2026-01-15', 0);
expect(runDueTemplateExpansion(db, BEFORE)).toEqual({ zones: [HONOLULU], created: 9, skipped: [] });
expect(runDueTemplateExpansion(db, BEFORE)).toEqual({ zones: [HONOLULU], created: 13, skipped: [] });
expect(shiftCount(db, chicago)).toBe(0);
expect(shiftCount(db, honolulu)).toBe(9);
expect(shiftCount(db, honolulu)).toBe(13);
expect(shiftCount(db, ended)).toBe(0);
expect(marks(db)).toEqual([{ scope: HONOLULU, local_date: '2026-01-14' }]);
expect(runDueTemplateExpansion(db, AT_ONE).zones).toEqual([CHICAGO]);
expect(shiftCount(db, chicago)).toBe(9);
expect(shiftCount(db, honolulu)).toBe(9);
expect(shiftCount(db, chicago)).toBe(13);
expect(shiftCount(db, honolulu)).toBe(13);
expect(shiftCount(db, ended)).toBe(0);
expect(runDueTemplateExpansion(db, AT_ONE)).toEqual({ zones: [], created: 0, skipped: [] });
expect(marks(db)).toEqual([
@@ -63,11 +63,11 @@ describe('daily weekly refill', () => {
runDueTemplateExpansion(db, AT_ONE);
const kept = db.prepare(`SELECT role AS role, cancelled AS cancelled FROM shifts WHERE occurrence_date = '2026-01-15'`).get();
expect(kept).toEqual({ role: 'Kept', cancelled: 1 });
expect(lastDate(db, eventId)).toBe('2026-03-12');
expect(lastDate(db, eventId)).toBe('2026-04-09');
runDueTemplateExpansion(db, NEXT_WEEK);
expect(lastDate(db, eventId)).toBe('2026-03-19');
expect(shiftCount(db, eventId)).toBe(10);
expect(lastDate(db, eventId)).toBe('2026-04-16');
expect(shiftCount(db, eventId)).toBe(14);
expect(db.prepare(`SELECT detail_json AS detail_json FROM audit`).all().map((row) => (row as { detail_json: string }).detail_json).join(' ')).not.toContain('@');
});
@@ -109,7 +109,7 @@ describe('daily weekly refill', () => {
} finally {
console.error = write;
}
expect(shiftCount(db, chicago)).toBe(9);
expect(shiftCount(db, chicago)).toBe(13);
expect(shiftCount(db, broken)).toBe(0);
expect(marks(db).map((row) => row.scope)).toEqual([CHICAGO]);
expect(errors.join(' ')).toContain('Not/AZone');
@@ -121,9 +121,9 @@ describe('daily weekly refill', () => {
const eventId = insertEvent(db, 'chicago', CHICAGO);
insertTemplate(db, eventId, 4, '2026-01-15');
const runner = startDailyExpansionRunner(db, () => AT_ONE);
expect(shiftCount(db, eventId)).toBe(9);
expect(shiftCount(db, eventId)).toBe(13);
runner.stop();
expect(shiftCount(db, eventId)).toBe(9);
expect(shiftCount(db, eventId)).toBe(13);
});
});
+2 -2
View File
@@ -190,9 +190,9 @@ describe('transactional mail', () => {
body,
});
expect(saved.status).toBe(303);
const home = await (await app.request('/')).text();
const home = await (await app.request('/?view=calendar')).text();
expect(home).not.toContain('listed@example.invalid');
expect(home).not.toContain('Listed Person');
expect(home).toContain('Listed Person');
expect(db.prepare("SELECT status FROM outbox").get()).toEqual({ status: 'pending' });
});
});
+203 -35
View File
@@ -2,11 +2,13 @@ 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';
@@ -27,20 +29,28 @@ describe('public pages', () => {
const html = await home.text();
expect(html).toContain('Weekly pantry');
expect(html).not.toContain('Upcoming shifts');
expect(html).toContain('Open Sorting');
expect(html).toContain('Full Intake');
expect(html).toContain('>Sign Up</a>');
expect(html).toContain('>List</a>');
expect(html).toContain('href="/?view=calendar">Calendar</a>');
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('Live Greeting');
expect(html).toContain('1/3 spots filled');
expect(html).toContain('1/1 spots filled');
expect(html).toContain('0/2 spots filled');
expect(html).toContain('1/4 spots filled');
expect(html).toContain('9:00 AM');
expect(html).toContain('CDT');
expect(html).toContain('October 15');
expect(html).toContain('October 2026');
expect(html).toContain('shift-calendar');
expect(html).toContain('class="cal-line"');
expect(html).toContain('class="cal-hold"');
expect(html).toContain('class="cal-detail"');
expect(html).toContain('>Sun</span>');
expect(html).toContain('October 14');
expect(html).toContain('October 21');
expect(html).toContain('No one signed up yet.');
expect(html).toContain('class="day-card"');
expect(html).toContain('class="shift-pane"');
expect(html.match(/class="day-card"/g)).toHaveLength(2);
expect(html.match(/class="shift-pane"/g)).toHaveLength(3);
expect(html).not.toContain('shift-calendar');
expect(html).not.toContain('Open Sorting');
expect(html).not.toContain('Full Intake');
expect(html).toContain('Today');
expect(html).toContain('aria-current="date"');
expect(html).toContain('In progress');
@@ -73,6 +83,7 @@ describe('public pages', () => {
expect(html).not.toContain('Hidden draft');
expect(html).not.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('<form');
@@ -81,7 +92,7 @@ describe('public pages', () => {
expect(html).not.toContain('<script>alert(1)</script>');
expect(html).toContain('href="/css/app.css?v=');
expect(html).toContain('href="/brand/tokens.css?v=');
expect(html).toContain(`href="/s/${ids.open}"`);
expect(html).toMatch(/href="\/s\/\d+"/);
expect(home.headers.get('content-security-policy')).toBe(CONTENT_SECURITY_POLICY);
expect(home.headers.get('referrer-policy')).toBe('no-referrer');
expect(home.headers.get('x-content-type-options')).toBe('nosniff');
@@ -95,12 +106,32 @@ describe('public pages', () => {
expect(eventHtml).toContain('&lt;script&gt;alert(1)&lt;/script&gt;');
expect(eventHtml).not.toContain('<script>alert(1)</script>');
expect(eventHtml).toContain('Sioux Center, Iowa');
expect(eventHtml).toContain('October 2026');
expect(eventHtml).toContain('shift-calendar');
expect(eventHtml).toContain('Wednesday Sorting');
expect(eventHtml).toContain('Lane Wednesday');
expect(eventHtml).toContain('Sign up');
expect(eventHtml).toContain('View shift');
expect(eventHtml).not.toContain('shift-calendar');
expect(eventHtml).not.toContain('November 2026');
expect(eventHtml).not.toContain('SECRET-PERSON-NOTE');
expect(eventHtml).not.toContain('lane.wednesday@example.invalid');
const calendar = await (await app.request('/?view=calendar')).text();
expect(calendar).toContain('shift-calendar');
expect(calendar).toContain('October 2026');
expect(calendar).toContain('Open Sorting');
expect(calendar).toContain('Full Intake');
expect(calendar).toContain('1/3 spots filled');
expect(calendar).toContain('1/1 spots filled');
expect(calendar).toContain('class="cal-line"');
expect(calendar).toContain('class="cal-hold"');
expect(calendar).toContain('class="cal-detail"');
expect(calendar).toContain('>Sun</span>');
expect(calendar).toContain('Secret Person');
expect(calendar).toContain('Lane Wednesday');
expect(calendar).toContain('View shift');
expect(calendar).toContain(`href="/s/${ids.open}"`);
expect(calendar).not.toContain('secret.person@example.invalid');
expect(calendar).not.toContain('SECRET-PERSON-NOTE');
expect(calendar).not.toContain('November 2026');
const shift = await app.request(`/s/${ids.open}`);
const shiftHtml = await shift.text();
@@ -122,6 +153,9 @@ describe('public pages', () => {
expect(shiftHtml).not.toContain('data-guardian');
expect(shiftHtml).not.toContain('I am under 18');
const css = await (await app.request('/css/app.css')).text();
expect(css).toContain('grid-template-columns: repeat(4, minmax(0, 1fr))');
expect(css).toContain('grid-template-columns: repeat(2, minmax(0, 1fr))');
expect(css).not.toContain('minmax(16rem, 1fr)');
expect(css).not.toContain('data-under-18');
expect(css).not.toContain('data-guardian');
expect(shiftHtml).not.toContain('SECRET-SHIFT-NOTE');
@@ -253,7 +287,7 @@ describe('public pages', () => {
expect(await health.json()).toEqual({ ok: true, database: 'ok' });
});
it('shows one month at a time and cycles between months that have shifts', async () => {
it('shows Wednesday cards by default and one calendar month at a time', async () => {
const { app, db } = await buildApp();
const event = db.prepare(`SELECT id AS id FROM events WHERE slug = 'weekly-pantry'`).get() as { id: number };
insertShift(db, event.id, 'November Sorting', '2026-11-04', '09:00', '12:00', 4, 0);
@@ -261,37 +295,162 @@ describe('public pages', () => {
insertShift(db, event.id, 'December Sorting', '2026-12-02', '09:00', '12:00', 4, 0);
const html = await (await app.request('/e/weekly-pantry')).text();
const home = await (await app.request('/')).text();
expect(html).toContain('October 2026');
expect(html).toContain('Next month');
expect(html).not.toContain('Previous month');
expect(html).not.toContain('November 2026');
expect(html).not.toContain('September');
expect(home).toContain('href="/?month=2026-11"');
expect(home).toContain('Next month');
expect(html).toContain('Open Sorting');
expect(html).not.toContain('November Sorting');
expect(html).toContain('href="/e/weekly-pantry?month=2026-11"');
expect(html.match(/class="cal-title"/g)).toHaveLength(1);
expect(html).toContain('Wednesday Sorting');
expect(html).toContain('November Sorting');
expect(html).toContain('December Sorting');
expect(html).not.toContain('Edge Sorting');
expect(html).not.toContain('Open Sorting');
expect(html).not.toContain('shift-calendar');
expect(html).not.toContain('Next month');
expect(home).toContain('href="/?view=calendar"');
expect(home).not.toContain('month=2026-11');
const november = await (await app.request('/e/weekly-pantry?month=2026-11')).text();
const october = await (await app.request('/e/weekly-pantry?view=calendar')).text();
expect(october).toContain('October 2026');
expect(october).toContain('Next month');
expect(october).not.toContain('Previous month');
expect(october).not.toContain('November 2026');
expect(october).not.toContain('September');
expect(october).toContain('Open Sorting');
expect(october).not.toContain('November Sorting');
expect(october).toContain('href="/e/weekly-pantry?view=calendar&amp;month=2026-11"');
expect(october.match(/class="cal-title"/g)).toHaveLength(1);
expect(home).not.toContain('href="/?month=2026-11"');
const november = await (await app.request('/e/weekly-pantry?view=calendar&month=2026-11')).text();
expect(november).toContain('November 2026');
expect(november).toContain('November Sorting');
expect(november).toContain('Edge Sorting');
expect(november).not.toContain('Open Sorting');
expect(november).toContain('Previous month');
expect(november).toContain('Next month');
expect(november).toContain('href="/e/weekly-pantry?month=2026-10"');
expect(november).toContain('href="/e/weekly-pantry?month=2026-12"');
expect(november).toContain('href="/e/weekly-pantry?view=calendar&amp;month=2026-10"');
expect(november).toContain('href="/e/weekly-pantry?view=calendar&amp;month=2026-12"');
expect(november.match(/class="role">Edge Sorting/g)).toHaveLength(1);
const december = await (await app.request('/e/weekly-pantry?month=2026-12')).text();
const december = await (await app.request('/e/weekly-pantry?view=calendar&month=2026-12')).text();
expect(december).toContain('December Sorting');
expect(december).toContain('Previous month');
expect(december).not.toContain('Next month');
expect(december).not.toContain('November Sorting');
const invalid = await (await app.request('/e/weekly-pantry?month=nope')).text();
const invalid = await (await app.request('/e/weekly-pantry?view=calendar&month=nope')).text();
expect(invalid).toContain('October 2026');
expect(invalid).toContain('Open Sorting');
const cardsDespiteMonth = await (await app.request('/e/weekly-pantry?month=2026-11')).text();
expect(cardsDespiteMonth).toContain('Wednesday Sorting');
expect(cardsDespiteMonth).not.toContain('shift-calendar');
});
it('lists only the next three months and refuses signup after that', async () => {
const { app, db, ids } = await buildApp();
const event = db.prepare(`SELECT id AS id FROM events WHERE slug = 'weekly-pantry'`).get() as { id: number };
const windowId = insertShift(db, event.id, 'Window Sorting', '2027-01-13', '09:00', '12:00', 3, 0);
const deadlineId = insertShift(db, event.id, 'Deadline Sorting', '2027-01-14', '09:00', '12:00', 3, 0);
const laterId = insertShift(db, event.id, 'Later Sorting', '2027-01-20', '09:00', '12:00', 3, 0);
insertShift(db, event.id, 'Spring Sorting', '2027-04-07', '09:00', '12:00', 3, 0);
const mail = {
baseUrl: 'http://127.0.0.1:3000',
basePath: '',
from: 'Hope Food Pantry <volunteer@example.invalid>',
replyTo: 'volunteer@example.invalid',
};
const windowSignup = reserveSignup(db, {
shiftId: windowId,
name: 'Window Person',
email: 'window.person@example.invalid',
phone: '712-555-0108',
notes: 'WINDOW-NOTE',
operationId: 'window-operation',
now: NOW,
mail,
});
expect(windowSignup.ok).toBe(true);
const cards = await (await app.request('/')).text();
expect(cards).toContain('Window Sorting');
expect(cards).toContain('Window Person');
expect(cards).not.toContain('window.person@example.invalid');
expect(cards).not.toContain('WINDOW-NOTE');
expect(cards).not.toContain('Deadline Sorting');
expect(cards).not.toContain('Later Sorting');
expect(cards).not.toContain('Spring Sorting');
expect(cards).toContain('Sign-up is open through January 14, 2027.');
const january = await (await app.request('/?view=calendar&month=2027-01')).text();
expect(january).toContain('January 2027');
expect(january).toContain('Window Sorting');
expect(january).toContain('Window Person');
expect(january).toContain('Deadline Sorting');
expect(january).not.toContain('Later Sorting');
expect(january).not.toContain('Spring Sorting');
expect(january).not.toContain('Next month');
const spring = await (await app.request('/?view=calendar&month=2027-04')).text();
expect(spring).toContain('October 2026');
expect(spring).not.toContain('Spring Sorting');
const laterPage = await app.request(`/s/${laterId}`);
const laterHtml = await laterPage.text();
expect(laterPage.status).toBe(200);
expect(laterHtml).toContain('Sign-up opens three months before this shift.');
expect(laterHtml).not.toContain('<form');
const deadlinePage = await (await app.request(`/s/${deadlineId}`)).text();
expect(deadlinePage).toContain('<form');
expect(deadlinePage).not.toContain('Sign-up opens three months before this shift.');
const early = reserveSignup(db, {
shiftId: laterId,
name: 'Later Person',
email: 'later.person@example.invalid',
phone: '712-555-0109',
notes: null,
operationId: 'later-operation',
now: NOW,
mail,
});
expect(early).toEqual({ ok: false, reason: 'early' });
expect(db.prepare("SELECT COUNT(*) AS n FROM signups WHERE email_norm = 'later.person@example.invalid'").get()).toEqual({ n: 0 });
const targets = listMoveTargets(db, event.id, ids.open, NOW, { publishedOnly: true, signupWindow: true });
expect(targets.map((target) => target.id)).not.toContain(laterId);
expect(targets.map((target) => target.id)).toContain(deadlineId);
const coordinatorTargets = listMoveTargets(db, event.id, ids.open, NOW);
expect(coordinatorTargets.map((target) => target.id)).toContain(laterId);
if (!windowSignup.ok) throw new Error('Window signup was not saved.');
const switched = switchSignup(db, windowSignup.signupId, laterId, 'switch-later', NOW, mail);
expect(switched.ok).toBe(false);
if (!switched.ok) expect(switched.error).toContain('three months');
expect(db.prepare('SELECT shift_id AS shift_id, status AS status FROM signups WHERE id = ?').get(windowSignup.signupId)).toEqual({
shift_id: windowId,
status: 'confirmed',
});
});
it('leaves a full shift on the list without a link', async () => {
const { app, db } = await buildApp();
const event = db.prepare(`SELECT id AS id FROM events WHERE slug = 'weekly-pantry'`).get() as { id: number };
const full = insertShift(db, event.id, 'Full Wednesday', '2026-10-28', '09:00', '12:00', 1, 0);
insertSignup(db, full, { name: 'Full Person', email: 'full.person@example.invalid' });
const html = await (await app.request('/')).text();
const start = html.indexOf('Full Wednesday');
const pane = html.slice(html.lastIndexOf('<section class="shift-pane"', start), html.indexOf('</section>', start));
expect(pane).toContain('1/1 spots filled');
expect(pane).toContain('class="btn-card is-static"');
expect(pane).toContain('>Full</span>');
expect(pane).toContain('Not accepting more signups');
expect(pane).not.toContain('View shift');
expect(pane).not.toContain('href=');
expect(pane).not.toContain('right-arrow');
expect(html).not.toContain(`href="/s/${full}"`);
const calendar = await (await app.request('/?view=calendar&month=2026-10')).text();
expect(calendar).toContain(`href="/s/${full}"`);
const openStart = html.indexOf('Wednesday Sorting');
const openPane = html.slice(html.lastIndexOf('<section class="shift-pane"', openStart), html.indexOf('</section>', openStart));
expect(openPane).toContain('>Sign up');
expect(openPane).toContain('href="/s/');
});
it('shows an empty list when nothing is upcoming', async () => {
@@ -336,6 +495,9 @@ function seedCatalog(db: import('better-sqlite3').Database) {
});
const open = insertShift(db, event, 'Open Sorting', '2026-10-15', '09:00', '12:00', 3, 0);
insertSignup(db, open);
const wednesday = insertShift(db, event, 'Wednesday Sorting', '2026-10-21', '09:00', '12:00', 4, 0);
insertSignup(db, wednesday, { name: 'Lane Wednesday', email: 'lane.wednesday@example.invalid' });
insertShift(db, event, 'Wednesday Greeting', '2026-10-21', '12:00', '15:00', 2, 0);
const full = insertShift(db, event, 'Full Intake', '2026-10-16', '09:00', '12:00', 1, 0);
insertSignup(db, full);
const cancelled = insertShift(db, event, 'Cancelled Distribution', '2026-10-17', '09:00', '12:00', 4, 1);
@@ -386,12 +548,18 @@ function versionedAsset(html: string, file: string): string {
return `${file}?v=${match[1]}`;
}
function insertSignup(db: import('better-sqlite3').Database, shiftId: number): void {
function insertSignup(
db: import('better-sqlite3').Database,
shiftId: number,
person?: { name: string; email: string },
): void {
const name = person?.name ?? 'Secret Person';
const email = person?.email ?? 'secret.person@example.invalid';
db.prepare(
`INSERT INTO signups (
shift_id, name, email, email_norm, is_minor, group_size, notes, status, reminders_off, created_at, updated_at
) VALUES (?, 'Secret Person', 'secret.person@example.invalid', 'secret.person@example.invalid', 0, 1, 'SECRET-PERSON-NOTE', 'confirmed', 0, '2026-10-01T15:00:00.000Z', '2026-10-01T15:00:00.000Z')`,
).run(shiftId);
) VALUES (?, ?, ?, ?, 0, 1, 'SECRET-PERSON-NOTE', 'confirmed', 0, '2026-10-01T15:00:00.000Z', '2026-10-01T15:00:00.000Z')`,
).run(shiftId, name, email, email);
}
describe('security headers', () => {
+11 -6
View File
@@ -22,7 +22,7 @@ afterEach(() => {
});
describe('weekly template expansion', () => {
it('adds the next eight weeks and leaves an existing occurrence alone', async () => {
it('adds the next three months and leaves an existing occurrence alone', async () => {
const db = await openDb();
const eventId = insertEvent(db, 'weekly', ZONE);
const templateId = insertTemplate(db, eventId, { weekday: 3, startsOn: '2026-10-14' });
@@ -40,7 +40,7 @@ describe('weekly template expansion', () => {
).run(eventId);
const first = expandTemplates(db, NOW);
expect(first).toEqual({ created: 8, templates: 1, skipped: [] });
expect(first).toEqual({ created: 13, templates: 1, skipped: [] });
const dates = db
.prepare(
`SELECT occurrence_date AS occurrence_date, role AS role, capacity AS capacity, cancelled AS cancelled, template_revision AS template_revision
@@ -57,6 +57,11 @@ describe('weekly template expansion', () => {
'2026-11-25',
'2026-12-02',
'2026-12-09',
'2026-12-16',
'2026-12-23',
'2026-12-30',
'2027-01-06',
'2027-01-13',
]);
expect(dates[0]).toMatchObject({ role: 'Kept', capacity: 2, cancelled: 1, template_revision: 1 });
expect(dates.slice(1).every((row) => row.role === 'Sorting' && row.capacity === 6 && row.cancelled === 0)).toBe(true);
@@ -71,7 +76,7 @@ describe('weekly template expansion', () => {
};
expect(audit.coordinator_id).toBeNull();
expect(audit.detail_json).not.toContain('@');
expect(JSON.parse(audit.detail_json)).toEqual({ templateId, created: 8 });
expect(JSON.parse(audit.detail_json)).toEqual({ templateId, created: 13 });
});
it('keeps 9:00 local on both sides of a daylight-saving change', async () => {
@@ -143,13 +148,13 @@ describe('add weekly shifts', () => {
expect(added.headers.get('location')).toBe(`/admin/events/${eventId}?notice=generated`);
const page = await app.request(added.headers.get('location') ?? '', { headers: { cookie } });
const html = await page.text();
expect(html).toContain('Weekly shifts for the next eight weeks are on the schedule.');
expect(html).toContain('Weekly shifts for the next three months are on the schedule.');
expect(html).toContain('Add weekly shifts');
expect(count(db, 'SELECT COUNT(*) AS n FROM shifts')).toBe(9);
expect(count(db, 'SELECT COUNT(*) AS n FROM shifts')).toBe(14);
const repeat = await postGenerate(app, eventId, cookie);
expect(repeat.headers.get('location')).toBe(`/admin/events/${eventId}?notice=generated`);
expect(count(db, 'SELECT COUNT(*) AS n FROM shifts')).toBe(9);
expect(count(db, 'SELECT COUNT(*) AS n FROM shifts')).toBe(14);
expect(count(db, "SELECT COUNT(*) AS n FROM audit WHERE action = 'template.expand'")).toBe(1);
const none = await postGenerate(app, empty, cookie);
+17
View File
@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest';
import { isWithinSignupWindow, signupDeadline, signupDeadlineLabel } from '../src/signup-window.js';
describe('signup window', () => {
it('opens signup through the same local date three months ahead', () => {
expect(signupDeadline('2026-10-14')).toBe('2027-01-14');
expect(signupDeadlineLabel('2026-10-14')).toBe('January 14, 2027');
expect(isWithinSignupWindow('2027-01-14', '2026-10-14')).toBe(true);
expect(isWithinSignupWindow('2027-01-15', '2026-10-14')).toBe(false);
});
it('uses the last valid day when the later month is shorter', () => {
expect(signupDeadline('2026-01-31')).toBe('2026-04-30');
expect(isWithinSignupWindow('2026-04-30', '2026-01-31')).toBe(true);
expect(isWithinSignupWindow('2026-05-01', '2026-01-31')).toBe(false);
});
});
+5 -5
View File
@@ -77,14 +77,14 @@ describe('weekly template editing', () => {
const generated = await postGenerate(app, eventId, cookie);
expect(generated.status).toBe(303);
const wednesdays = count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Sorting'");
expect(wednesdays).toBe(9);
expect(wednesdays).toBe(14);
const friday = await postTemplate(app, eventId, cookie, { weekday: '5', role: 'Intake', capacity: '4' });
expect(friday.headers.get('location')).toBe(`/admin/events/${eventId}?notice=template-saved`);
await postGenerate(app, eventId, cookie);
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Sorting'")).toBe(wednesdays);
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake' AND capacity = 4")).toBe(8);
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE template_revision = 1")).toBe(wednesdays + 8);
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake' AND capacity = 4")).toBe(13);
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE template_revision = 1")).toBe(wednesdays + 13);
const templateId = (
db.prepare("SELECT id AS id FROM shift_templates WHERE role = 'Intake'").get() as { id: number }
@@ -95,14 +95,14 @@ describe('weekly template editing', () => {
revision: 2,
role: 'Packing',
});
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake'")).toBe(8);
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake'")).toBe(13);
const ended = await postEnd(app, eventId, templateId, cookie);
expect(ended.headers.get('location')).toBe(`/admin/events/${eventId}?notice=template-ended`);
const page = await app.request(`/admin/events/${eventId}?notice=template-ended`, { headers: { cookie } });
const html = await page.text();
expect(html).toContain('This weekly template has ended. Shifts already on the schedule stay.');
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake'")).toBe(8);
expect(count(db, "SELECT COUNT(*) AS n FROM shifts WHERE role = 'Intake'")).toBe(13);
expect(count(db, 'SELECT COUNT(*) AS n FROM outbox')).toBe(1);
});
});