diff --git a/packages/core/src/app/init.test.ts b/packages/core/src/app/init.test.ts index d24a11122..d8400f475 100644 --- a/packages/core/src/app/init.test.ts +++ b/packages/core/src/app/init.test.ts @@ -1,27 +1,7 @@ -import { createMockUtils, pickDefault } from '@logto/shared/esm'; +import { pickDefault } from '@logto/shared/esm'; import Koa from 'koa'; -import { emptyMiddleware } from '#src/utils/test-utils.js'; - const { jest } = import.meta; -const { mockEsm } = createMockUtils(jest); - -const middlewareList = [ - 'error-handler', - 'i18next', - 'audit-log', - 'oidc-error-handler', - 'slonik-error-handler', - 'spa-proxy', -].map((name) => { - const mock = jest.fn(() => emptyMiddleware); - mockEsm(`#src/middleware/koa-${name}.js`, () => ({ - default: mock, - ...(name === 'audit-log' && { LogEntry: jest.fn() }), - })); - - return mock; -}); const initI18n = await pickDefault(import('../i18n/init.js')); const initApp = await pickDefault(import('./init.js')); @@ -34,10 +14,6 @@ describe('App Init', () => { await initI18n(); await initApp(app); - for (const middleware of middlewareList) { - expect(middleware).toBeCalled(); - } - expect(listenMock).toBeCalled(); }); }); diff --git a/packages/core/src/tenants/Tenant.test.ts b/packages/core/src/tenants/Tenant.test.ts new file mode 100644 index 000000000..b6771649c --- /dev/null +++ b/packages/core/src/tenants/Tenant.test.ts @@ -0,0 +1,39 @@ +import { createMockUtils, pickDefault } from '@logto/shared/esm'; + +import { createMockProvider } from '#src/test-utils/oidc-provider.js'; +import { emptyMiddleware } from '#src/utils/test-utils.js'; + +const { jest } = import.meta; +const { mockEsm, mockEsmDefault } = createMockUtils(jest); + +const middlewareList = [ + 'error-handler', + 'i18next', + 'audit-log', + 'oidc-error-handler', + 'slonik-error-handler', + 'spa-proxy', +].map((name) => { + const mock = jest.fn(() => emptyMiddleware); + mockEsm(`#src/middleware/koa-${name}.js`, () => ({ + default: mock, + ...(name === 'audit-log' && { LogEntry: jest.fn() }), + })); + + return mock; +}); + +// eslint-disable-next-line unicorn/consistent-function-scoping +mockEsmDefault('#src/oidc/init.js', () => () => createMockProvider); + +const Tenant = await pickDefault(import('./Tenant.js')); + +describe('Tenant', () => { + it('should call middleware factories', () => { + const _ = new Tenant('foo'); + + for (const middleware of middlewareList) { + expect(middleware).toBeCalled(); + } + }); +});