Adapt the failing direct sign-up tests to the declarer notification decision

This commit is contained in:
Sylvain Duchesne
2026-11-06 23:09:48 +01:00
parent 9cbe78948b
commit af0cba6920
7 changed files with 178 additions and 3 deletions
+95 -3
View File
@@ -866,13 +866,105 @@ describe('registration — a direct sign-up: a Join naming an event itself', ()
expect(w.logs.error).toEqual([]);
});
test("a direct sign-up notifies nobody: the declarer of an event is not its host", async () => {
const readsOf = (w, uri) => w.calls.filter(c => ['pod-resources.get', 'pod-collections.getItems'].includes(c.action) && (c.params.resourceUri ?? c.params.collectionUri) === uri);
const expectAnonymous = (w, n) => {
expect(n.recipientUri).toBe(ALICE);
expect(JSON.stringify(n.template)).not.toContain('participantName');
expect(n).not.toHaveProperty('participantName');
expect(n).not.toHaveProperty('activity');
expect(JSON.stringify(n)).not.toContain(BOB);
expect(readsOf(w, contactsOf(BOB))).toEqual([]);
};
test("a direct sign-up notifies the event's declarer, anonymously", async () => {
const j = join(PLAIN);
const w = plainWorld([j]);
await emitJoin(w, j);
expect(attendees(w, PLAIN)).toEqual([plainUrn()]);
expect(w.calls.some(c => c.action === 'pod-notifications.send')).toBe(false);
expect(w.state.notifications).toEqual([]);
expect(w.state.notifications).toHaveLength(1);
const [n] = w.state.notifications;
expectAnonymous(w, n);
expect(n.template.title.fr).toContain('Un participant a rejoint');
expect(n.template.title.en).toContain('A participant joined');
expect(n.eventUri).toBe(PLAIN);
expect(Object.values(n)).toContain('Evénement plain');
expect(JSON.stringify(n.template)).not.toContain('Evénement plain');
expect(n.template.title.fr).toContain('{{{');
expect(n.template.actions).toHaveLength(1);
expect(n.template.actions[0].link).toContain('/events/{{encodeUri eventUri}}');
expect(n.template.actions[0].link).not.toContain('meeting-points');
});
test('a Leave naming the event notifies the declarer, anonymously', async () => {
const j = join(PLAIN);
const l = leave(PLAIN);
const w = plainWorld([j, l]);
await emitJoin(w, j);
await emitLeave(w, l);
expect(w.state.notifications).toHaveLength(2);
const n = w.state.notifications[1];
expectAnonymous(w, n);
expect(n.template.title.fr).toContain('Un participant a quitté');
expect(n.template.title.en).toContain('A participant left');
expect(n.eventUri).toBe(PLAIN);
});
test('a repeated direct Join notifies once; a Leave of someone never signed up notifies no one', async () => {
const first = join(PLAIN, T0, BOB, 1);
const again = join(PLAIN, T1, BOB, 2);
const stray = leave(PLAIN, T1, CAROL, 1);
const w = plainWorld([first, again, stray]);
await emitJoin(w, first);
await emitJoin(w, again);
expect(w.state.notifications).toHaveLength(1);
await emitLeave(w, stray);
expect(w.state.notifications).toHaveLength(1);
});
test('a failed declarer notification does not fail the direct sign-up', async () => {
const j = join(PLAIN);
const w = plainWorld([j], { fail: { notify: true } });
await emitJoin(w, j);
expect(ledgerOf(w, PLAIN).change).toBe('join');
expect(attendees(w, PLAIN)).toEqual([plainUrn()]);
expect(participations(w)).toEqual([PLAIN]);
expect(w.logs.error.some(m => m.includes('Could not notify'))).toBe(true);
});
test('leaving the event and its meeting point notifies the declarer and the host, each once', async () => {
const DAVE_EVENT = `${DAVE}/data/events/festival`;
const acts = [join(DAVE_EVENT), join(MP1), leave(DAVE_EVENT, T1), leave(MP1, T1)];
const w = setup({
acts,
stored: {
[DAVE_EVENT]: plainEvent(DAVE_EVENT, { 'dc:creator': DAVE }),
[MP1]: meetingPoint(MP1, { context: DAVE_EVENT })
}
});
await emitJoin(w, acts[0]);
await emitJoin(w, acts[1]);
w.state.notifications.length = 0;
await emitLeave(w, acts[2]);
await emitLeave(w, acts[3]);
expect(w.state.notifications).toHaveLength(2);
expect(w.state.notifications.map(n => n.recipientUri).sort()).toEqual([ALICE, DAVE].sort());
for (const n of w.state.notifications) {
expect(n.template.title.fr).toContain('Un participant a quitté');
expect(n).not.toHaveProperty('participantName');
expect(JSON.stringify(n)).not.toContain(BOB);
}
});
test('the same person carries a different URN on another event (R7e)', async () => {
const OTHER = `${ALICE}/data/events/other`;
const a = join(PLAIN, T0, BOB, 1);
const b = join(OTHER, T0, BOB, 2);
const w = setup({ acts: [a, b], stored: { [PLAIN]: plainEvent(PLAIN), [OTHER]: plainEvent(OTHER) } });
await emitJoin(w, a);
await emitJoin(w, b);
expect(attendees(w, PLAIN)).toEqual([plainUrn(BOB, PLAIN)]);
expect(attendees(w, OTHER)).toEqual([plainUrn(BOB, OTHER)]);
expect(attendees(w, PLAIN)[0]).not.toBe(attendees(w, OTHER)[0]);
});
test("the participant carries the SAME URN in the event's own list and in its meeting points' lists (R5, R6)", async () => {