feat: enhance party size management with coordinator notifications

Updated the changePartySize function to include mail identity and notify coordinators when a signup's party size changes. Enhanced the writePartySize function to queue notices for coordinators, detailing changes in group size. Added new tests to verify the notification logic for party size adjustments, ensuring accurate communication of changes to coordinators.
This commit is contained in:
blake committed 2026-11-02 12:04:20 -06:00
1 parent 17ca2f9dfb
commit cd71fa2e59
5 files changed
+98 -9

No files matched your search

+31 -1
View File
@@ -9,7 +9,7 @@ import { loadConfig } from '../src/config.js';
import { openAppDatabase } from '../src/db.js';
import { deliverDueMail } from '../src/mail/deliver.js';
import type { Mailer } from '../src/mail/types.js';
import { cancelSignup, reserveSignup, type ReserveInput } from '../src/signup.js';
import { cancelSignup, changePartySize, reserveSignup, type ReserveInput } from '../src/signup.js';
import { devEnv } from './env.js';
const NOW = '2026-10-14T18:00:00.000Z';
@@ -188,6 +188,36 @@ describe('coordinator roster notices', () => {
});
});
it('tells coordinators when a signup changes from one person to eight, once for that new size', async () => {
const { db, shiftId } = await buildDb();
db.prepare('UPDATE shifts SET capacity = 10 WHERE id = ?').run(shiftId);
insertCoordinator(db, 'ada@example.invalid', 'Ada Admin', 1);
const saved = reserveSignup(db, reservation(shiftId, { groupSize: 1, operationId: 'party-source' }));
if (!saved.ok || !saved.manageToken) throw new Error('Signup was not saved.');
expect(changePartySize(db, saved.manageToken, 8, NOW, MAIL)).toEqual({ ok: true, groupSize: 8, changed: true });
const party = db
.prepare(`SELECT subject, body_text, dedupe_key FROM outbox WHERE kind = 'notice' AND subject LIKE 'Pat Review changed to %'`)
.get() as { subject: string; body_text: string; dedupe_key: string };
expect(party.subject).toBe('Pat Review changed to 8 people for Sorting');
expect(party.body_text).toContain('from 1 person to 8 people');
expect(party.dedupe_key).toBe(`notice:party:v1:8:${saved.signupId}:ada@example.invalid`);
expect(party.body_text).toContain('That takes 7 more spots.');
expect(party.body_text).toContain(`/admin/shifts/${shiftId}`);
expect(party.body_text).not.toContain('/m/');
expect(db.prepare(`SELECT kind FROM outbox WHERE kind != 'notice'`).all()).toEqual([{ kind: 'confirmation' }]);
expect(changePartySize(db, saved.manageToken, 8, NOW, MAIL)).toEqual({ ok: true, groupSize: 8, changed: false });
expect(changePartySize(db, saved.manageToken, 5, NOW, MAIL)).toEqual({ ok: true, groupSize: 5, changed: true });
expect(db.prepare(`SELECT subject FROM outbox WHERE kind = 'notice' AND subject LIKE 'Pat Review changed to %' ORDER BY subject`).all()).toEqual([
{ subject: 'Pat Review changed to 5 people for Sorting' },
{ subject: 'Pat Review changed to 8 people for Sorting' },
]);
expect(db.prepare(`SELECT status FROM outbox WHERE kind = 'notice' AND subject = 'Pat Review signed up for Sorting'`).get()).toEqual({
status: 'pending',
});
});
it('stops a waiting notice when an administrator is removed or the sign-in address is replaced', async () => {
const { db, shiftId } = await buildDb();
const ada = insertCoordinator(db, 'ada@example.invalid', 'Ada Admin', 1);