mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 14:36:31 +00:00
style: format server and shared with prettier
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.
This commit is contained in:
@@ -3,6 +3,11 @@
|
||||
* PluginsService holds the storage/masking logic (separately tested); here we prove the
|
||||
* gates (runtime off / no user / inactive plugin) and the delegation.
|
||||
*/
|
||||
import type { PluginsRepository } from '../../../src/db/repositories/Plugins.repository';
|
||||
import type { PluginRuntimeService } from '../../../src/nest/plugins/plugin-runtime.service';
|
||||
import { PluginUserSettingsController } from '../../../src/nest/plugins/plugin-user-settings.controller';
|
||||
import type { PluginsService } from '../../../src/nest/plugins/plugins.service';
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
const { pluginsEnabled, getMock } = vi.hoisted(() => ({
|
||||
@@ -11,32 +16,40 @@ const { pluginsEnabled, getMock } = vi.hoisted(() => ({
|
||||
}));
|
||||
vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));
|
||||
|
||||
import { PluginUserSettingsController } from '../../../src/nest/plugins/plugin-user-settings.controller';
|
||||
import type { PluginRuntimeService } from '../../../src/nest/plugins/plugin-runtime.service';
|
||||
import type { PluginsService } from '../../../src/nest/plugins/plugins.service';
|
||||
import type { PluginsRepository } from '../../../src/db/repositories/Plugins.repository';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const req = (id?: number) => ({ user: id === undefined ? undefined : { id } }) as any;
|
||||
function ctrl() {
|
||||
const svc = {
|
||||
userSettingsFields: vi.fn(async () => [{ key: 'apiKey', secret: true }]),
|
||||
getUserConfig: vi.fn(async () => ({ apiKey: '••••••••' })),
|
||||
updateUserConfig: vi.fn(async (_id: string, _uid: number, patch: Record<string, unknown>) => ({ ...patch, apiKey: '••••••••' })),
|
||||
updateUserConfig: vi.fn(async (_id: string, _uid: number, patch: Record<string, unknown>) => ({
|
||||
...patch,
|
||||
apiKey: '••••••••',
|
||||
})),
|
||||
} as unknown as PluginsService;
|
||||
// The controller now also takes the runtime (for settings-page actions).
|
||||
const runtime = { actionsOf: vi.fn(async () => []), invokeAction: vi.fn(async () => ({ ok: true })) } as unknown as PluginRuntimeService;
|
||||
const runtime = {
|
||||
actionsOf: vi.fn(async () => []),
|
||||
invokeAction: vi.fn(async () => ({ ok: true })),
|
||||
} as unknown as PluginRuntimeService;
|
||||
// PUC1 (Plan 3j Task 5) — the active-plugin guard is now Plugins.repository.ts#existsActive.
|
||||
const plugins = { existsActive: vi.fn(async () => !!getMock()) } as unknown as PluginsRepository;
|
||||
return { c: new PluginUserSettingsController(svc, runtime, plugins), svc, runtime };
|
||||
}
|
||||
|
||||
describe('PluginUserSettingsController', () => {
|
||||
beforeEach(() => { pluginsEnabled.mockReturnValue(true); getMock.mockReturnValue({ 1: 1 }); });
|
||||
beforeEach(() => {
|
||||
pluginsEnabled.mockReturnValue(true);
|
||||
getMock.mockReturnValue({ 1: 1 });
|
||||
});
|
||||
|
||||
it('GET returns fields + masked config for a bound user; empty when gated', async () => {
|
||||
const { c } = ctrl();
|
||||
expect(await c.get('p', req(5))).toEqual({ fields: [{ key: 'apiKey', secret: true }], config: { apiKey: '••••••••' }, actions: [] });
|
||||
expect(await c.get('p', req(5))).toEqual({
|
||||
fields: [{ key: 'apiKey', secret: true }],
|
||||
config: { apiKey: '••••••••' },
|
||||
actions: [],
|
||||
});
|
||||
pluginsEnabled.mockReturnValue(false);
|
||||
expect(await c.get('p', req(5))).toEqual({ fields: [], config: {}, actions: [] });
|
||||
pluginsEnabled.mockReturnValue(true);
|
||||
@@ -47,7 +60,9 @@ describe('PluginUserSettingsController', () => {
|
||||
|
||||
it('POST delegates the patch for a bound user; empty when gated', async () => {
|
||||
const { c, svc } = ctrl();
|
||||
expect(await c.update('p', { config: { units: 'metric' } }, req(5))).toEqual({ config: { units: 'metric', apiKey: '••••••••' } });
|
||||
expect(await c.update('p', { config: { units: 'metric' } }, req(5))).toEqual({
|
||||
config: { units: 'metric', apiKey: '••••••••' },
|
||||
});
|
||||
expect(svc.updateUserConfig).toHaveBeenCalledWith('p', 5, { units: 'metric' });
|
||||
// a non-object body → empty patch (no throw)
|
||||
await c.update('p', {}, req(5));
|
||||
|
||||
Reference in New Issue
Block a user