mirror of
https://github.com/logto-io/logto.git
synced 2025-01-13 21:30:30 -05:00
b42f4ba1ff
implement admin console welcome page
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { MountedApps } from '@/env-set';
|
|
import { hasActiveUsers } from '@/queries/user';
|
|
import { createContextWithRouteParameters } from '@/utils/test-utils';
|
|
|
|
import koaWelcomeProxy from './koa-welcome-proxy';
|
|
|
|
jest.mock('@/queries/user', () => ({
|
|
hasActiveUsers: jest.fn(),
|
|
}));
|
|
|
|
describe('koaWelcomeProxy', () => {
|
|
const next = jest.fn();
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('should redirect to admin console if has AdminUsers', async () => {
|
|
(hasActiveUsers as jest.Mock).mockResolvedValue(true);
|
|
const ctx = createContextWithRouteParameters({
|
|
url: `/${MountedApps.Welcome}`,
|
|
});
|
|
|
|
await koaWelcomeProxy()(ctx, next);
|
|
|
|
expect(ctx.redirect).toBeCalledWith(`/${MountedApps.Console}`);
|
|
expect(next).not.toBeCalled();
|
|
});
|
|
|
|
it('should redirect to welcome page if has no Users', async () => {
|
|
(hasActiveUsers as jest.Mock).mockResolvedValue(false);
|
|
const ctx = createContextWithRouteParameters({
|
|
url: `/${MountedApps.Welcome}`,
|
|
});
|
|
|
|
await koaWelcomeProxy()(ctx, next);
|
|
expect(ctx.redirect).toBeCalledWith(`/${MountedApps.Console}/welcome`);
|
|
expect(next).not.toBeCalled();
|
|
});
|
|
});
|