2023-09-11 12:30:39 +03:00
|
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
2023-09-01 22:41:29 +03:00
|
|
|
import test from 'ava';
|
2023-04-18 06:24:44 +03:00
|
|
|
|
2023-09-15 10:34:14 +03:00
|
|
|
import { Config, ConfigModule } from '../src/config';
|
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 () => {
|
2023-09-11 12:30:39 +03:00
|
|
|
module = await Test.createTestingModule({
|
2023-04-18 06:24:44 +03:00
|
|
|
imports: [ConfigModule.forRoot()],
|
|
|
|
}).compile();
|
|
|
|
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 => {
|
|
|
|
t.true(typeof config.host === 'string');
|
|
|
|
t.is(config.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 => {
|
2023-04-18 06:24:44 +03:00
|
|
|
const module = await Test.createTestingModule({
|
|
|
|
imports: [
|
|
|
|
ConfigModule.forRoot({
|
|
|
|
host: 'testing',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}).compile();
|
|
|
|
const config = module.get(Config);
|
|
|
|
|
2023-09-05 11:01:45 +03:00
|
|
|
t.is(config.host, 'testing');
|
2023-04-18 06:24:44 +03:00
|
|
|
});
|