2024-05-28 09:43:53 +03:00
|
|
|
import { TestingModule } from '@nestjs/testing';
|
2023-09-01 22:41:29 +03:00
|
|
|
import test from 'ava';
|
2023-04-18 06:24:44 +03:00
|
|
|
|
2024-01-12 07:18:39 +03:00
|
|
|
import { Config, ConfigModule } from '../src/fundamentals/config';
|
2024-05-28 09:43:53 +03:00
|
|
|
import { createTestingModule } from './utils';
|
2023-04-18 06:24:44 +03:00
|
|
|
|
|
|
|
let config: Config;
|
2023-09-11 12:30:39 +03:00
|
|
|
let module: TestingModule;
|
2023-09-01 22:41:29 +03:00
|
|
|
test.beforeEach(async () => {
|
2024-07-23 13:39:33 +03:00
|
|
|
module = await createTestingModule({}, false);
|
2023-04-18 06:24:44 +03:00
|
|
|
config = module.get(Config);
|
|
|
|
});
|
|
|
|
|
2023-09-11 12:30:39 +03:00
|
|
|
test.afterEach.always(async () => {
|
|
|
|
await module.close();
|
|
|
|
});
|
|
|
|
|
2023-09-01 22:41:29 +03:00
|
|
|
test('should be able to get config', t => {
|
2024-05-28 09:43:53 +03:00
|
|
|
t.true(typeof config.server.host === 'string');
|
2024-08-14 16:02:16 +03:00
|
|
|
t.is(config.projectRoot, process.cwd());
|
2024-02-02 11:32:06 +03:00
|
|
|
t.is(config.NODE_ENV, 'test');
|
2023-04-18 06:24:44 +03:00
|
|
|
});
|
|
|
|
|
2023-09-01 22:41:29 +03:00
|
|
|
test('should be able to override config', async t => {
|
2024-05-28 09:43:53 +03:00
|
|
|
const module = await createTestingModule({
|
2023-04-18 06:24:44 +03:00
|
|
|
imports: [
|
|
|
|
ConfigModule.forRoot({
|
2024-05-28 09:43:53 +03:00
|
|
|
server: {
|
|
|
|
host: 'testing',
|
|
|
|
},
|
2023-04-18 06:24:44 +03:00
|
|
|
}),
|
|
|
|
],
|
2024-05-28 09:43:53 +03:00
|
|
|
});
|
2023-04-18 06:24:44 +03:00
|
|
|
const config = module.get(Config);
|
|
|
|
|
2024-05-28 09:43:53 +03:00
|
|
|
t.is(config.server.host, 'testing');
|
2024-07-23 13:39:33 +03:00
|
|
|
|
|
|
|
await module.close();
|
2023-04-18 06:24:44 +03:00
|
|
|
});
|