mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 23:46:35 +00:00
lint + prettier
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
* (runtime off / no user / inactive plugin) and that the callback always redirects to
|
||||
* an in-app path with the right status, never leaking an error.
|
||||
*/
|
||||
import type { PluginsRepository } from '../../../src/db/repositories/Plugins.repository';
|
||||
import { PluginOAuthController } from '../../../src/nest/plugins/oauth/plugin-oauth.controller';
|
||||
import type { PluginOAuthService } from '../../../src/nest/plugins/oauth/plugin-oauth.service';
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
const { pluginsEnabled, getMock } = vi.hoisted(() => ({
|
||||
@@ -12,14 +16,16 @@ const { pluginsEnabled, getMock } = vi.hoisted(() => ({
|
||||
}));
|
||||
vi.mock('../../../src/nest/plugins/kill-switch', () => ({ pluginsEnabled }));
|
||||
|
||||
import { PluginOAuthController } from '../../../src/nest/plugins/oauth/plugin-oauth.controller';
|
||||
import type { PluginOAuthService } from '../../../src/nest/plugins/oauth/plugin-oauth.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 fakeRes() {
|
||||
const res = { redirectedTo: '' as string, redirect(loc: string) { res.redirectedTo = loc; return res; } };
|
||||
const res = {
|
||||
redirectedTo: '' as string,
|
||||
redirect(loc: string) {
|
||||
res.redirectedTo = loc;
|
||||
return res;
|
||||
},
|
||||
};
|
||||
return res;
|
||||
}
|
||||
function ctrl(over: Partial<PluginOAuthService> = {}) {
|
||||
@@ -36,7 +42,10 @@ function ctrl(over: Partial<PluginOAuthService> = {}) {
|
||||
}
|
||||
|
||||
describe('PluginOAuthController', () => {
|
||||
beforeEach(() => { pluginsEnabled.mockReturnValue(true); getMock.mockReturnValue({ 1: 1 }); });
|
||||
beforeEach(() => {
|
||||
pluginsEnabled.mockReturnValue(true);
|
||||
getMock.mockReturnValue({ 1: 1 });
|
||||
});
|
||||
|
||||
it('status is gated: runtime off / no user / inactive → not configured', async () => {
|
||||
expect(await ctrl().c.status('p', req(5))).toEqual({ configured: true, connected: false });
|
||||
@@ -60,7 +69,11 @@ describe('PluginOAuthController', () => {
|
||||
expect(okRes.redirectedTo).toBe('/settings?oauth=p:connected');
|
||||
|
||||
const failRes = fakeRes();
|
||||
await ctrl({ completeCallback: vi.fn(async () => { throw new Error('boom'); }) }).c.callback('p', 'code', 'state', undefined, req(5), failRes as never);
|
||||
await ctrl({
|
||||
completeCallback: vi.fn(async () => {
|
||||
throw new Error('boom');
|
||||
}),
|
||||
}).c.callback('p', 'code', 'state', undefined, req(5), failRes as never);
|
||||
expect(failRes.redirectedTo).toBe('/settings?oauth=p:failed'); // never leaks the error
|
||||
|
||||
const denyRes = fakeRes();
|
||||
|
||||
Reference in New Issue
Block a user