Events 3.0: auto-connect, demo people in Accounts, e2e; import.finish checks the subs

- contracts 1.8.0 / Accounts 1.1.0: import.finish lists the subs the product
  relies on; Accounts checks each is held, not deleted and known to it (the
  count+hash failed a second move after Undo once someone had joined
  through Accounts).
- Events: connects to the church's Accounts once the Hub lists it;
  moveNewPeople (demo data, people added after the move); set-demo moves
  demo people; e2e/sign-in-accounts.spec.ts with Accounts in memory and an
  e2e-only /api rewrite. test:accounts 14/14; Jest auto-connect tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 14:28:54 +02:00
co-authored by Claude Opus 5.5
parent c627c61de1
commit 63d36c3ecf
24 changed files with 466 additions and 63 deletions
@@ -231,6 +231,23 @@ describe('signing out, and Accounts\' calls', () => {
assert.equal((await eventsDb.user.findUnique({ where: { id: ids.thandi } }) as { name: string }).name, 'Thandi M. Mokoena');
});
test('people added here after the move (demo data) are moved too, and can sign in', async () => {
const id = crypto.randomUUID();
await eventsUser({ id, name: 'Demo Person', email: 'demo.person@hope.test', password: await bcrypt.hash('Demo-pass-123', 4) });
const r = await move.moveNewPeople(null);
assert.equal(r.moved, 1);
assert.equal((await eventsDb.user.findUnique({ where: { id } }) as { accountId: string }).accountId, id);
const signed = await signInThroughEvents(new Browser(), 'demo.person@hope.test', 'Demo-pass-123', '/');
assert.ok('token' in signed && signed.token);
});
test('someone new to Events signs in with a church account they made elsewhere', async () => {
const a = await h.makeAccount({ email: 'newcomer@hope.test', password: 'Newcomer-pass-1', name: 'Newcomer' });
const r = await signInThroughEvents(new Browser(), 'newcomer@hope.test', 'Newcomer-pass-1', '/events');
assert.ok('token' in r && r.token, JSON.stringify(r));
assert.equal((await eventsDb.user.findUnique({ where: { id: r.user.id } }) as { accountId: string; role: string }).accountId, a.id);
});
test('Undo goes back to Events\' own sign-in', async () => {
await move.undo({ id: ids.sam, role: 'admin' });
mode.forgetMode();
@@ -239,3 +256,14 @@ describe('signing out, and Accounts\' calls', () => {
assert.equal(res.status, 200);
});
});
describe('moving again after Undo', () => {
test('works, including someone who joined through Accounts in between', async () => {
mode.forgetMode();
assert.equal(await mode.authMode(), 'local');
const report = await move.move({ actor: { id: ids.sam, role: 'admin' }, adminIds: [] });
assert.equal(report.created, 0, 'nobody new to move');
mode.forgetMode();
assert.equal(await mode.authMode(), 'accounts');
});
});
@@ -0,0 +1,48 @@
// 3.0.0 (docs/EVENTS-3.0-PLAN.md §9): connecting to the church's Accounts once the Hub lists it.
const mockSettings = new Map<string, string>();
const mockConnects: unknown[][] = [];
let mockListed: { installId: string; product: string }[] = [];
let mockLink: object | null = null;
jest.mock('../src/links/connect', () => ({ connectTo: async (...args: unknown[]) => { mockConnects.push(args); mockLink = { installId: args[0] }; } }));
jest.mock('../src/links/store', () => ({ linkedProducts: async () => mockListed }));
jest.mock('../src/accounts/client', () => ({ accountsLink: async () => mockLink }));
jest.mock('../src/accounts/mode', () => ({
getSetting: async (k: string) => mockSettings.get(k) ?? null,
setSetting: async (k: string, v: string | null) => { if (v === null) mockSettings.delete(k); else mockSettings.set(k, v); },
}));
import { AUTO_KEY, connectAccountsIfListed } from '../src/accounts/autoConnect';
const ACCOUNTS = '9a4c2f1e-7b3d-4e5a-8c6f-0d1e2f3a4b5c';
beforeEach(() => {
mockSettings.clear();
mockConnects.length = 0;
mockListed = [];
mockLink = null;
});
test('connects to the Accounts the Hub lists, as the system, once', async () => {
mockListed = [{ installId: 'w1', product: 'website' }, { installId: ACCOUNTS, product: 'accounts' }];
expect(await connectAccountsIfListed()).toBe('connected');
expect(mockConnects).toEqual([[ACCOUNTS, { id: null, role: 'system' }, null, expect.any(Date)]]);
expect(mockSettings.has(AUTO_KEY)).toBe(true);
// An admin disconnects later: it isn't connected again.
mockLink = null;
expect(await connectAccountsIfListed()).toBe('skipped');
expect(mockConnects).toHaveLength(1);
});
test('nothing listed yet: tries again at the next heartbeat', async () => {
expect(await connectAccountsIfListed()).toBe('skipped');
expect(mockSettings.has(AUTO_KEY)).toBe(false);
});
test('already connected by an admin: just remembers it', async () => {
mockLink = { installId: ACCOUNTS };
mockListed = [{ installId: ACCOUNTS, product: 'accounts' }];
expect(await connectAccountsIfListed()).toBe('skipped');
expect(mockConnects).toEqual([]);
expect(mockSettings.has(AUTO_KEY)).toBe(true);
});