0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-13 21:30:30 -05:00
logto/packages/core/src/middleware/koa-welcome-proxy.test.ts
simeng-li b42f4ba1ff
feat(ac): implement admin console welcome page (#1139)
implement admin console welcome page
2022-06-20 10:58:27 +08:00

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();
});
});