93 lines
2.2 KiB
TypeScript
93 lines
2.2 KiB
TypeScript
/**
|
|
* Test Setup for @stock-bot/config Library
|
|
*
|
|
* Provides common setup and utilities for testing configuration modules.
|
|
*/
|
|
|
|
// Set NODE_ENV immediately at module load time
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
// Store original environment variables
|
|
const originalEnv = process.env;
|
|
|
|
// Note: Bun provides its own test globals, no need to import from @jest/globals
|
|
beforeEach(() => {
|
|
// Reset environment variables to original state
|
|
process.env = { ...originalEnv };
|
|
// Ensure NODE_ENV is set to test by default
|
|
process.env.NODE_ENV = 'test';
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Clear environment
|
|
});
|
|
|
|
afterAll(() => {
|
|
// Restore original environment
|
|
process.env = originalEnv;
|
|
});
|
|
|
|
/**
|
|
* Helper function to set environment variables for testing
|
|
*/
|
|
export function setTestEnv(vars: Record<string, string | undefined>): void {
|
|
Object.assign(process.env, vars);
|
|
}
|
|
|
|
/**
|
|
* Helper function to clear specific environment variables
|
|
*/
|
|
export function clearEnvVars(vars: string[]): void {
|
|
vars.forEach(varName => {
|
|
delete process.env[varName];
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Helper function to get a clean environment for testing
|
|
*/
|
|
export function getCleanEnv(): typeof process.env {
|
|
return {
|
|
NODE_ENV: 'test',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Helper function to create minimal required environment variables
|
|
*/
|
|
export function getMinimalTestEnv(): Record<string, string> {
|
|
return {
|
|
NODE_ENV: 'test',
|
|
// Logging
|
|
LOG_LEVEL: 'info', // Changed from 'error' to 'info' to match test expectations
|
|
// Database
|
|
POSTGRES_HOST: 'localhost',
|
|
POSTGRES_PORT: '5432',
|
|
POSTGRES_DATABASE: 'test_db',
|
|
POSTGRES_USERNAME: 'test_user',
|
|
POSTGRES_PASSWORD: 'test_pass',
|
|
// QuestDB
|
|
QUESTDB_HOST: 'localhost',
|
|
QUESTDB_HTTP_PORT: '9000',
|
|
QUESTDB_PG_PORT: '8812',
|
|
// MongoDB
|
|
MONGODB_HOST: 'localhost',
|
|
MONGODB_PORT: '27017',
|
|
MONGODB_DATABASE: 'test_db',
|
|
MONGODB_USERNAME: 'test_user',
|
|
MONGODB_PASSWORD: 'test_pass',
|
|
// Dragonfly
|
|
DRAGONFLY_HOST: 'localhost',
|
|
DRAGONFLY_PORT: '6379',
|
|
// Monitoring
|
|
PROMETHEUS_PORT: '9090',
|
|
GRAFANA_PORT: '3000',
|
|
// Data Providers
|
|
DATA_PROVIDER_API_KEY: 'test_key',
|
|
// Risk
|
|
RISK_MAX_POSITION_SIZE: '0.1',
|
|
RISK_MAX_DAILY_LOSS: '0.05',
|
|
// Admin
|
|
ADMIN_PORT: '8080',
|
|
};
|
|
}
|