mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 02:16:16 +00:00
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
// config-options.spec.ts
|
|
|
|
import { buildConfigOptions } from './config-options';
|
|
import * as path from 'path';
|
|
import { ConfigModuleOptions } from '@nestjs/config';
|
|
import { Environment } from '../enums';
|
|
|
|
describe('buildConfigOptions', () => {
|
|
const baseConfigDir = path.join(__dirname, '..', '..', 'config');
|
|
|
|
it('should return global config options with .env and development environment file path', () => {
|
|
process.env.NODE_ENV = Environment.DEV;
|
|
|
|
const configOptions: ConfigModuleOptions = buildConfigOptions();
|
|
|
|
expect(configOptions.isGlobal).toBe(true);
|
|
expect(configOptions.envFilePath).toEqual(['.env', path.join(baseConfigDir, Environment.DEV + '.env')]);
|
|
});
|
|
|
|
it('should return global config options with .env and production environment file path', () => {
|
|
process.env.NODE_ENV = Environment.PROD;
|
|
|
|
const configOptions: ConfigModuleOptions = buildConfigOptions();
|
|
|
|
expect(configOptions.isGlobal).toBe(true);
|
|
expect(configOptions.envFilePath).toEqual(['.env', path.join(baseConfigDir, Environment.PROD + '.env')]);
|
|
});
|
|
|
|
it('should use default env file if NODE_ENV is not set', () => {
|
|
delete process.env.NODE_ENV;
|
|
|
|
const configOptions: ConfigModuleOptions = buildConfigOptions();
|
|
|
|
expect(configOptions.isGlobal).toBe(true);
|
|
expect(configOptions.envFilePath).toEqual([
|
|
'.env',
|
|
path.join(baseConfigDir, 'undefined.env'), // This simulates no NODE_ENV
|
|
]);
|
|
});
|
|
});
|