mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
724c88c201
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
68 lines
3.2 KiB
TypeScript
68 lines
3.2 KiB
TypeScript
/**
|
|
* The admin-scope preference matrix, after the two routes moved off AdminController
|
|
* next to NotificationPreferencesService, which owns it. The 'admin' scope argument
|
|
* they always passed is now written once, at the only place that uses it.
|
|
*/
|
|
import type { NotificationPreferencesService } from '../../../src/nest/notifications/notification-preferences.service';
|
|
import { AdminNotificationPreferencesController } from '../../../src/nest/notifications/notifications.controller';
|
|
import { NotificationsModule } from '../../../src/nest/notifications/notifications.module';
|
|
import type { User } from '../../../src/types';
|
|
import { expectRegisteredController } from '../../helpers/module-providers';
|
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
const admin = { id: 1, role: 'admin' } as User;
|
|
|
|
function controller() {
|
|
const prefs = {
|
|
getPreferencesMatrix: vi.fn(() => ({ rows: [{ event: 'trip_reminder' }] })),
|
|
setAdminPreferences: vi.fn(),
|
|
getInstanceDefaults: vi.fn(() => ({ defaults: { trip_invite: { email: 'off' } } })),
|
|
setInstanceDefaults: vi.fn(),
|
|
} as unknown as NotificationPreferencesService;
|
|
return { c: new AdminNotificationPreferencesController(prefs), prefs };
|
|
}
|
|
|
|
describe('AdminNotificationPreferencesController', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('ADMINPREF-001 GET asks for the admin scope, not the user one', async () => {
|
|
const { c, prefs } = controller();
|
|
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', 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(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', async () => {
|
|
const { c, prefs } = controller();
|
|
await c.get({ id: 7, role: 'admin' } as User);
|
|
expect(prefs.getPreferencesMatrix).toHaveBeenCalledWith(7, 'admin', 'admin');
|
|
});
|
|
|
|
it('ADMINPREF-005 the defaults for users are read and written for the acting admin (#1536)', async () => {
|
|
const { c, prefs } = controller();
|
|
expect(await c.getDefaults(admin)).toEqual({ defaults: { trip_invite: { email: 'off' } } });
|
|
expect(prefs.getInstanceDefaults).toHaveBeenCalledWith(1);
|
|
expect(await c.setDefaults(admin, { defaults: { trip_invite: { email: 'off' } } } as never)).toEqual({
|
|
defaults: { trip_invite: { email: 'off' } },
|
|
});
|
|
expect(prefs.setInstanceDefaults).toHaveBeenCalledWith({ trip_invite: { email: 'off' } });
|
|
});
|
|
|
|
it('ADMINPREF-004 the class is listed in its module controllers', () => {
|
|
expectRegisteredController(NotificationsModule, AdminNotificationPreferencesController);
|
|
});
|
|
});
|