feat: show the private signup address and let coordinators correct contacts

The confirmation page prints the full manage URL so it can be copied before the browser drops it. A saved contact can be corrected in place, and shift menus group choices by date.
This commit is contained in:
blake committed 2026-10-19 12:12:23 -05:00
1 parent 322c575fcb
commit 5e0e4a55a8
14 files changed
+439 -36

No files matched your search

+2
View File
@@ -520,6 +520,8 @@ describe('coordinator screens', () => {
const page = await app.request(`/admin/shifts/${sourceId}`, { headers: { cookie } });
const html = await page.text();
expect(optionValues(html, 'destination')).toEqual([String(destinationId)]);
expect(html).toContain('<optgroup label="Friday, October 23, 2026">');
expect(html).toContain('>Distribution, October 23, 2026, 9:00 AM to 12:00 PM CDT<');
const moved = await postMove(app, cookie, signupId, html, String(destinationId));
expect(moved.status).toBe(303);
expect(moved.headers.get('location')).toBe(`/admin/shifts/${destinationId}?notice=moved`);
+27
View File
@@ -170,6 +170,8 @@ describe('manage-link switch', () => {
const html = await before.text();
expect(before.status).toBe(200);
expect(optionValues(html)).toEqual([String(destinationId)]);
expect(html).toContain('<optgroup label="Saturday, October 17, 2026">');
expect(html).toContain('>Distribution, October 17, 2026, 9:00 AM to 12:00 PM CDT<');
expect(html).toContain('>Switch<');
expect(db.prepare('SELECT status, shift_id FROM signups').get()).toEqual({ status: 'confirmed', shift_id: shiftId });
@@ -285,6 +287,31 @@ describe('manage-link switch', () => {
});
expect(db.prepare("SELECT COUNT(*) AS n FROM audit WHERE action = 'signup.switch'").get()).toEqual({ n: 0 });
});
it('groups switch choices under each date', async () => {
const { app, db, shiftId } = await buildApp();
const eventId = Number((db.prepare('SELECT id AS id FROM events').get() as { id: number }).id);
const morningId = insertShift(db, eventId, 'Intake', '2026-10-17T14:00:00.000Z', '2026-10-17T16:00:00.000Z', 2);
const afternoonId = insertShift(db, eventId, 'Distribution', '2026-10-17T19:00:00.000Z', '2026-10-17T21:00:00.000Z', 2);
const tuesdayId = insertShift(db, eventId, 'Packing', '2026-10-20T14:00:00.000Z', '2026-10-20T17:00:00.000Z', 2);
const { managePath } = await openManage(app, shiftId, 'date.switch@example.invalid', '203.0.113.45');
const html = await (await app.request(managePath)).text();
const select = /<select\b[^>]*\bid="switch-to"[^>]*>([\s\S]*?)<\/select>/.exec(html)?.[1] ?? '';
const saturday = select.indexOf('<optgroup label="Saturday, October 17, 2026">');
const tuesday = select.indexOf('<optgroup label="Tuesday, October 20, 2026">');
const morning = select.indexOf(`<option value="${morningId}">`);
const afternoon = select.indexOf(`<option value="${afternoonId}">`);
const later = select.indexOf(`<option value="${tuesdayId}">`);
expect(saturday).toBeGreaterThanOrEqual(0);
expect(morning).toBeGreaterThan(saturday);
expect(afternoon).toBeGreaterThan(morning);
expect(tuesday).toBeGreaterThan(afternoon);
expect(later).toBeGreaterThan(tuesday);
expect(select).toContain('>Intake, October 17, 2026, 9:00 AM to 11:00 AM CDT<');
expect(select).toContain('>Distribution, October 17, 2026, 2:00 PM to 4:00 PM CDT<');
expect(select).toContain('>Packing, October 20, 2026, 9:00 AM to 12:00 PM CDT<');
expect(select.match(/<optgroup/g)).toHaveLength(2);
});
});
async function buildApp(options?: { capacity?: number }) {
+181 -2
View File
@@ -385,8 +385,15 @@ describe('contact pages', () => {
expect(personHtml).toContain('555-0100');
expect(personHtml).toContain('id="add-shift"');
expect(personHtml).toContain('Choose a shift');
expect(personHtml).toContain(`<option value="${openId}">`);
expect(personHtml).toContain(`<option value="${unpublishedId}">`);
const addMenu = /<select\b[^>]*\bid="add-shift"[^>]*>([\s\S]*?)<\/select>/.exec(personHtml)?.[1] ?? '';
const wednesday = addMenu.indexOf('<optgroup label="Wednesday, October 21, 2026">');
const thursday = addMenu.indexOf('<optgroup label="Thursday, October 22, 2026">');
expect(wednesday).toBeGreaterThanOrEqual(0);
expect(addMenu.indexOf(`<option value="${openId}">`)).toBeGreaterThan(wednesday);
expect(thursday).toBeGreaterThan(wednesday);
expect(addMenu.indexOf(`<option value="${unpublishedId}">`)).toBeGreaterThan(thursday);
expect(addMenu).toContain('>Weekly pantry: Sorting, October 21, 2026, 9:00 AM to 12:00 PM CDT<');
expect(addMenu).toContain('>Soup kitchen: Serving, October 22, 2026, 9:00 AM to 12:00 PM CDT (not on the public list)<');
expect(personHtml).toContain('Serving');
expect(personHtml).toContain('(not on the public list)');
expect(personHtml).not.toContain('Closing');
@@ -512,6 +519,157 @@ describe('contact pages', () => {
expect(count(db, 'SELECT COUNT(*) AS n FROM contacts')).toBe(2);
expect(await (await app.request('/')).text()).not.toContain('ada@example.invalid');
});
it('corrects a saved name, email, or phone without creating another person', async () => {
const { app, db } = await buildApp();
const cookie = await signIn(app, db);
const openId = insertShift(db);
await postFile(
app,
cookie,
'First Name,Last Name,Email,Phone\nPat,-,pat@example.invalid,7125550101\nPat,Other,pat@example.invalid,222\n',
);
const contactId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = '-'`).get() as { id: number }).id;
const otherId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = 'Other'`).get() as { id: number }).id;
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('value="Pat"');
expect(personHtml).toContain('value="-"');
expect(personHtml).toContain('value="pat@example.invalid"');
expect(personHtml).toContain('value="712-555-0101"');
expect(personHtml).toContain('Add to this shift');
const loggedOut = await app.request(`/admin/contacts/${contactId}`, { method: 'POST' });
expect(loggedOut.status).toBe(303);
expect(db.prepare('SELECT last_name, phone FROM contacts WHERE id = ?').get(contactId)).toEqual({
last_name: '-',
phone: '712-555-0101',
});
const stale = await postCorrect(app, cookie, contactId, {
firstName: 'Pat',
lastName: 'Review',
email: 'pat@example.invalid',
phone: '7125550199',
csrf: 'nope',
});
expect(stale.status).toBe(403);
expect(db.prepare('SELECT last_name FROM contacts WHERE id = ?').get(contactId)).toEqual({ last_name: '-' });
const corrected = await postCorrect(app, cookie, contactId, {
firstName: 'pat',
lastName: 'review',
email: 'Pat@Example.invalid',
phone: '7125550199',
});
expect(corrected.status).toBe(303);
expect(corrected.headers.get('location')).toBe(`/admin/contacts/${contactId}?notice=contact-corrected`);
const after = await app.request(corrected.headers.get('location') ?? '', { headers: { cookie } });
const afterHtml = await after.text();
expect(afterHtml).toContain('That contact is corrected.');
expect(afterHtml).toContain('Pat Review');
expect(afterHtml).toContain('value="Review"');
expect(afterHtml).toContain('value="712-555-0199"');
expect(db.prepare('SELECT id, first_name, last_name, email, phone FROM contacts ORDER BY id').all()).toEqual([
{ id: contactId, first_name: 'Pat', last_name: 'Review', email: 'pat@example.invalid', phone: '712-555-0199' },
{ id: otherId, first_name: 'Pat', last_name: 'Other', email: 'pat@example.invalid', phone: '222' },
]);
const correctAudit = db.prepare(`SELECT detail_json AS detail_json FROM audit WHERE action = 'contacts.correct'`).get() as {
detail_json: string;
};
expect(correctAudit.detail_json).toBe(`{"id":${contactId}}`);
expect(correctAudit.detail_json).not.toContain('@');
expect(count(db, 'SELECT COUNT(*) AS n FROM signups')).toBe(0);
expect(count(db, `SELECT COUNT(*) AS n FROM outbox WHERE kind = 'confirmation'`)).toBe(0);
const added = await postContactShift(app, cookie, contactId, openId, afterHtml, {});
expect(added.status).toBe(303);
expect(db.prepare(`SELECT name AS name, phone AS phone FROM signups WHERE email_norm = 'pat@example.invalid'`).get()).toEqual({
name: 'Pat Review',
phone: '712-555-0199',
});
expect(count(db, 'SELECT COUNT(*) AS n FROM contacts')).toBe(2);
const same = await postCorrect(app, cookie, contactId, {
firstName: 'Pat',
lastName: 'Review',
email: 'pat@example.invalid',
phone: '712-555-0199',
});
expect(same.headers.get('location')).toBe(`/admin/contacts/${contactId}?notice=contact-same`);
expect(count(db, `SELECT COUNT(*) AS n FROM audit WHERE action = 'contacts.correct'`)).toBe(1);
const renamedEmail = await postCorrect(app, cookie, contactId, {
firstName: 'Pat',
lastName: 'Review',
email: 'Patrick@Example.invalid',
phone: '712-555-0199',
});
expect(renamedEmail.headers.get('location')).toBe(`/admin/contacts/${contactId}?notice=contact-corrected`);
expect(db.prepare('SELECT email, phone FROM contacts WHERE id = ?').get(contactId)).toEqual({
email: 'patrick@example.invalid',
phone: '712-555-0199',
});
expect(db.prepare('SELECT email FROM contacts WHERE id = ?').get(otherId)).toEqual({ email: 'pat@example.invalid' });
const taken = await postCorrect(app, cookie, contactId, {
firstName: 'Pat',
lastName: 'Other',
email: 'pat@example.invalid',
phone: '712-555-0199',
});
expect(taken.status).toBe(400);
const takenHtml = await taken.text();
expect(takenHtml).toContain('That name and email are already saved as another contact.');
expect(takenHtml).toContain('value="Other"');
expect(db.prepare('SELECT first_name, last_name, email FROM contacts WHERE id = ?').get(contactId)).toEqual({
first_name: 'Pat',
last_name: 'Review',
email: 'patrick@example.invalid',
});
expect(count(db, 'SELECT COUNT(*) AS n FROM contacts')).toBe(2);
const cleared = await postCorrect(app, cookie, contactId, {
firstName: 'Pat',
lastName: 'Review',
email: 'patrick@example.invalid',
phone: '',
});
expect(cleared.status).toBe(303);
expect(db.prepare('SELECT phone FROM contacts WHERE id = ?').get(contactId)).toEqual({ phone: null });
expect(db.prepare(`SELECT phone AS phone FROM signups WHERE email_norm = 'pat@example.invalid'`).get()).toEqual({
phone: '712-555-0199',
});
const invalid = await postCorrect(app, cookie, contactId, {
firstName: '',
lastName: 'Review',
email: 'not-an-email',
phone: '7125550199',
});
expect(invalid.status).toBe(400);
const invalidHtml = await invalid.text();
expect(invalidHtml).toContain('Enter a first name.');
expect(invalidHtml).toContain('Enter an email address.');
expect(db.prepare('SELECT first_name, email, phone FROM contacts WHERE id = ?').get(contactId)).toEqual({
first_name: 'Pat',
email: 'patrick@example.invalid',
phone: null,
});
const missing = await postCorrect(app, cookie, 999, {
firstName: 'Pat',
lastName: 'Review',
email: 'patrick@example.invalid',
phone: '',
});
expect(missing.status).toBe(404);
expect(count(db, `SELECT COUNT(*) AS n FROM audit WHERE action = 'contacts.correct'`)).toBe(3);
});
});
async function openDb() {
@@ -670,6 +828,27 @@ async function postContactShift(
});
}
async function postCorrect(
app: Awaited<ReturnType<typeof buildApp>>['app'],
cookie: string,
contactId: number,
fields: { firstName: string; lastName: string; email: string; phone?: string; csrf?: string },
) {
const current = await app.request('/admin/contacts', { headers: { cookie } });
const token = fields.csrf ?? (/name="csrf" value="([^"]*)"/.exec(await current.text())?.[1] ?? '');
return app.request(`/admin/contacts/${contactId}`, {
method: 'POST',
headers: { origin: ORIGIN, 'content-type': 'application/x-www-form-urlencoded', cookie },
body: new URLSearchParams({
csrf: token,
first_name: fields.firstName,
last_name: fields.lastName,
email: fields.email,
phone: fields.phone ?? '',
}),
});
}
async function postManual(
app: Awaited<ReturnType<typeof buildApp>>['app'],
cookie: string,
+24
View File
@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest';
import { groupShiftTargets } from '../src/shift-options.js';
import type { MoveTarget } from '../src/admin/store.js';
function target(id: number, date: string, dateLabel: string): MoveTarget {
return { id, date, dateLabel, label: `Shift ${id}` };
}
describe('shift menu groups', () => {
it('keeps same-day shifts together and leaves a later repeat of that date in place', () => {
const groups = groupShiftTargets([
target(1, '2026-10-20', 'Tuesday, October 20, 2026'),
target(2, '2026-10-20', 'Tuesday, October 20, 2026'),
target(3, '2026-10-21', 'Wednesday, October 21, 2026'),
target(4, '2026-10-20', 'Tuesday, October 20, 2026'),
]);
expect(groups.map((group) => group.targets.map((item) => item.id))).toEqual([[1, 2], [3], [4]]);
expect(groups.map((group) => group.dateLabel)).toEqual([
'Tuesday, October 20, 2026',
'Wednesday, October 21, 2026',
'Tuesday, October 20, 2026',
]);
});
});
+9 -3
View File
@@ -51,9 +51,11 @@ describe('capacity-safe signup', () => {
expect(confirmed.status).toBe(200);
expect(confirmedHtml).toContain('Pat Review');
expect(confirmedHtml).toContain('A confirmation email is on the way');
expect(confirmedHtml).toContain('Cancel or switch shifts');
expect(confirmedHtml).toContain('Save the address below');
expect(confirmedHtml).toContain('This browser keeps it for a few minutes');
const managePath = confirmedHtml.match(/href="(\/m\/[^"]+)"/)?.[1];
expect(managePath).toBeTruthy();
expect(confirmedHtml).toContain(`>http://127.0.0.1:3000${managePath}<`);
expect(cookie).not.toContain(managePath?.slice(3) ?? 'missing-token');
const manage = await app.request(managePath ?? '/m/missing');
const manageHtml = await manage.text();
@@ -81,9 +83,11 @@ describe('capacity-safe signup', () => {
const again = await postSignup(app, shiftId, { name: 'Pat Review', email: 'pat.review@example.invalid' }, { ip: '203.0.113.21' });
expect(again.status).toBe(409);
const againHtml = await again.text();
expect(againHtml).toContain('That person is already signed up for this shift.');
expect(againHtml).toContain('That person is already signed up for this shift. Use the link in the confirmation email.');
expect(againHtml).not.toContain('already registered');
expect(againHtml).not.toContain('duplicate');
expect(againHtml).not.toContain(managePath ?? '/m/');
expect(againHtml).not.toContain('/m/');
expect(db.prepare("SELECT COUNT(*) AS n FROM signups WHERE status = 'confirmed'").get()).toEqual({ n: 1 });
});
@@ -105,7 +109,9 @@ describe('capacity-safe signup', () => {
]);
const again = await postSignup(app, shiftId, { name: 'sam review', email: 'home@example.invalid' }, { ip: '203.0.113.93' });
expect(again.status).toBe(409);
expect(await again.text()).toContain('That person is already signed up for this shift.');
const againHtml = await again.text();
expect(againHtml).toContain('That person is already signed up for this shift. Use the link in the confirmation email.');
expect(againHtml).not.toContain('/m/');
expect(db.prepare("SELECT COUNT(*) AS n FROM signups WHERE status = 'confirmed'").get()).toEqual({ n: 2 });
});