refactor(plugins): async DB-touching methods; transactions through UnitOfWork

This commit is contained in:
jubnl
2026-09-22 00:00:53 +02:00
parent e413308227
commit e28dc6de28
68 changed files with 743 additions and 706 deletions
@@ -25,24 +25,24 @@ describe('AdminNotificationPreferencesController', () => {
vi.clearAllMocks();
});
it('ADMINPREF-001 GET asks for the admin scope, not the user one', () => {
it('ADMINPREF-001 GET asks for the admin scope, not the user one', async () => {
const { c, prefs } = controller();
expect(c.get(admin)).toEqual({ rows: [{ event: 'trip_reminder' }] });
expect(await c.get(admin)).toEqual({ rows: [{ event: 'trip_reminder' }] });
expect(prefs.getPreferencesMatrix).toHaveBeenCalledWith(1, 'admin', 'admin');
});
it('ADMINPREF-002 PUT persists, then answers with the REFRESHED matrix', () => {
it('ADMINPREF-002 PUT persists, then answers with the REFRESHED matrix', async () => {
const { c, prefs } = controller();
// The admin panel renders straight from this response, so returning the write
// result instead of a fresh read would leave it showing stale rows.
expect(c.set(admin, { trip_reminder: { email: true } } as never)).toEqual({ rows: [{ event: 'trip_reminder' }] });
expect(await c.set(admin, { trip_reminder: { email: true } } as never)).toEqual({ rows: [{ event: 'trip_reminder' }] });
expect(prefs.setAdminPreferences).toHaveBeenCalledWith(1, { trip_reminder: { email: true } });
expect(prefs.getPreferencesMatrix).toHaveBeenCalledWith(1, 'admin', 'admin');
});
it('ADMINPREF-003 the acting user drives the lookup, never a body field', () => {
it('ADMINPREF-003 the acting user drives the lookup, never a body field', async () => {
const { c, prefs } = controller();
c.get({ id: 7, role: 'admin' } as User);
await c.get({ id: 7, role: 'admin' } as User);
expect(prefs.getPreferencesMatrix).toHaveBeenCalledWith(7, 'admin', 'admin');
});