mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-20 05:56:53 +00:00
lint + prettier
This commit is contained in:
@@ -4,21 +4,31 @@
|
||||
* flag, that link validates its body, and that reload maps a re-consent error to 409
|
||||
* exactly like activate does. The runtime is mocked — this is the HTTP glue only.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import { HttpException } from '@nestjs/common';
|
||||
import { PluginsController } from '../../../src/nest/plugins/plugins.controller';
|
||||
import { PluginConsentRequired } from '../../../src/nest/plugins/plugin-runtime.service';
|
||||
import type { RuntimeEnvService } from '../../../src/nest/app-config/runtime-env.service';
|
||||
import { PluginConsentRequired } from '../../../src/nest/plugins/plugin-runtime.service';
|
||||
import { PluginsController } from '../../../src/nest/plugins/plugins.controller';
|
||||
import { HttpException } from '@nestjs/common';
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const ctrl = (runtime: any) => new PluginsController({} as any, runtime, {} as any, { isManaged: () => false } as unknown as RuntimeEnvService);
|
||||
const ctrl = (runtime: any) =>
|
||||
new PluginsController({} as any, runtime, {} as any, { isManaged: () => false } as unknown as RuntimeEnvService);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const status = async (p: Promise<any>): Promise<number> =>
|
||||
p.then(() => -1, (e) => (e instanceof HttpException ? e.getStatus() : 0));
|
||||
p.then(
|
||||
() => -1,
|
||||
(e) => (e instanceof HttpException ? e.getStatus() : 0),
|
||||
);
|
||||
|
||||
describe('PluginsController dev-link endpoints', () => {
|
||||
beforeEach(() => { process.env.TREK_PLUGINS_ENABLED = 'true'; });
|
||||
afterEach(() => { delete process.env.TREK_PLUGINS_DEV_LINK; delete process.env.TREK_PLUGINS_ENABLED; });
|
||||
beforeEach(() => {
|
||||
process.env.TREK_PLUGINS_ENABLED = 'true';
|
||||
});
|
||||
afterEach(() => {
|
||||
delete process.env.TREK_PLUGINS_DEV_LINK;
|
||||
delete process.env.TREK_PLUGINS_ENABLED;
|
||||
});
|
||||
|
||||
it('POST /link is 403 unless dev-link is enabled, 400 without a path, and delegates when enabled', async () => {
|
||||
const runtime = { link: vi.fn(async () => ({ id: 'x', version: '1.0.0', replaced: false })) };
|
||||
@@ -34,7 +44,11 @@ describe('PluginsController dev-link endpoints', () => {
|
||||
|
||||
it('POST /link surfaces a runtime error as 400', async () => {
|
||||
process.env.TREK_PLUGINS_DEV_LINK = '1';
|
||||
const runtime = { link: vi.fn(async () => { throw new Error('no build'); }) };
|
||||
const runtime = {
|
||||
link: vi.fn(async () => {
|
||||
throw new Error('no build');
|
||||
}),
|
||||
};
|
||||
expect(await status(ctrl(runtime).link({ path: '/abs' }))).toBe(400);
|
||||
});
|
||||
|
||||
@@ -48,7 +62,9 @@ describe('PluginsController dev-link endpoints', () => {
|
||||
it('POST /:id/reload maps a re-consent error to 409 and otherwise returns the live status', async () => {
|
||||
process.env.TREK_PLUGINS_DEV_LINK = '1';
|
||||
const consent = {
|
||||
reload: vi.fn(async () => { throw new PluginConsentRequired('needs consent', ['db:read:trips'], []); }),
|
||||
reload: vi.fn(async () => {
|
||||
throw new PluginConsentRequired('needs consent', ['db:read:trips'], []);
|
||||
}),
|
||||
isActive: () => false,
|
||||
};
|
||||
expect(await status(ctrl(consent).reload('p'))).toBe(409);
|
||||
@@ -56,7 +72,12 @@ describe('PluginsController dev-link endpoints', () => {
|
||||
const ok = { reload: vi.fn(async () => {}), isActive: () => true };
|
||||
expect(await ctrl(ok).reload('p')).toEqual({ status: 'active' });
|
||||
|
||||
const bad = { reload: vi.fn(async () => { throw new Error('boom'); }), isActive: () => false };
|
||||
const bad = {
|
||||
reload: vi.fn(async () => {
|
||||
throw new Error('boom');
|
||||
}),
|
||||
isActive: () => false,
|
||||
};
|
||||
expect(await status(ctrl(bad).reload('p'))).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user