test: Implement the structure of mocking appConfig options
This commit is contained in:
@@ -1,6 +1,16 @@
|
|||||||
import { Model } from 'objection';
|
import { Model } from 'objection';
|
||||||
import { client as knex } from '../../src/config/database';
|
import { client as knex } from '../../src/config/database';
|
||||||
import logger from '../../src/helpers/logger';
|
import logger from '../../src/helpers/logger';
|
||||||
|
import { mockConfigState, resetMockConfig } from './set-mock-config';
|
||||||
|
|
||||||
|
jest.mock('../../src/config/app', () => ({
|
||||||
|
...jest.requireActual('../../src/config/app').default,
|
||||||
|
get isCloud() {
|
||||||
|
return mockConfigState.isCloud !== undefined
|
||||||
|
? mockConfigState.isCloud
|
||||||
|
: jest.requireActual('../../src/config/app').default.isCloud;
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
global.beforeAll(async () => {
|
global.beforeAll(async () => {
|
||||||
global.knex = null;
|
global.knex = null;
|
||||||
@@ -23,6 +33,7 @@ global.afterEach(async () => {
|
|||||||
Model.knex(knex);
|
Model.knex(knex);
|
||||||
|
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
resetMockConfig();
|
||||||
});
|
});
|
||||||
|
|
||||||
global.afterAll(async () => {
|
global.afterAll(async () => {
|
||||||
|
13
packages/backend/test/setup/set-mock-config.ts
Normal file
13
packages/backend/test/setup/set-mock-config.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
export const mockConfigState = {
|
||||||
|
isCloud: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const resetMockConfig = () => {
|
||||||
|
for (const key in mockConfigState) {
|
||||||
|
delete (mockConfigState as any)[key];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const setMockConfig = (config: Partial<typeof mockConfigState>) => {
|
||||||
|
Object.assign(mockConfigState, config);
|
||||||
|
};
|
Reference in New Issue
Block a user