2022-12-12 00:43:23 -05:00
|
|
|
/**
|
|
|
|
* Setup environment variables for unit test
|
|
|
|
*/
|
|
|
|
|
2023-09-25 03:16:04 -05:00
|
|
|
import en from '@logto/phrases/lib/locales/en/index.js';
|
2022-12-26 07:12:19 -05:00
|
|
|
import { createMockUtils } from '@logto/shared/esm';
|
2023-09-25 03:16:04 -05:00
|
|
|
import { init } from 'i18next';
|
2022-12-12 00:43:23 -05:00
|
|
|
|
|
|
|
const { jest } = import.meta;
|
2023-02-12 10:37:47 -05:00
|
|
|
const { mockEsm, mockEsmDefault } = createMockUtils(jest);
|
2022-12-12 00:43:23 -05:00
|
|
|
|
2023-01-11 03:41:53 -05:00
|
|
|
process.env.DB_URL = 'postgres://mock.db.url';
|
|
|
|
process.env.ENDPOINT = 'https://logto.test';
|
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
2023-02-09 05:31:14 -05:00
|
|
|
/* Mock for EnvSet */
|
2023-01-11 03:41:53 -05:00
|
|
|
mockEsm('#src/libraries/logto-config.js', () => ({
|
|
|
|
createLogtoConfigLibrary: () => ({ getOidcConfigs: () => ({}) }),
|
|
|
|
}));
|
|
|
|
|
2024-05-17 03:02:05 -05:00
|
|
|
mockEsm('#src/env-set/preconditions.js', () => ({
|
|
|
|
checkPreconditions: () => true,
|
2023-01-11 03:41:53 -05:00
|
|
|
}));
|
|
|
|
|
|
|
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
|
|
mockEsmDefault('#src/env-set/oidc.js', () => () => ({
|
|
|
|
issuer: 'https://logto.test/oidc',
|
2023-02-11 01:38:16 -05:00
|
|
|
cookieKeys: [],
|
|
|
|
privateJwks: [],
|
|
|
|
publicJwks: [],
|
2023-01-11 03:41:53 -05:00
|
|
|
}));
|
2023-02-09 05:31:14 -05:00
|
|
|
/* End */
|
2023-01-11 03:41:53 -05:00
|
|
|
|
2022-12-12 00:43:23 -05:00
|
|
|
// Logger is not considered in all test cases
|
|
|
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
|
|
mockEsm('koa-logger', () => ({ default: () => (_, next) => next() }));
|
2023-09-25 03:16:04 -05:00
|
|
|
|
|
|
|
// Init i18next and load en locale only
|
|
|
|
await init({
|
|
|
|
fallbackLng: 'en',
|
|
|
|
supportedLngs: ['en'],
|
|
|
|
resources: { en },
|
|
|
|
});
|