test: Implement the structure of mocking appConfig options

This commit is contained in:
Faruk AYDIN
2023-10-18 15:45:54 +02:00
parent 14886d42e8
commit b2205097da
2 changed files with 24 additions and 0 deletions

View File

@@ -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 () => {

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