fixed some lint issues

This commit is contained in:
Boki 2025-06-26 16:11:58 -04:00
parent 8680b6ec20
commit a700818a06
15 changed files with 1574 additions and 1319 deletions

View file

@ -1,23 +1,11 @@
import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test';
import { beforeEach, describe, expect, it } from 'bun:test';
import { z } from 'zod';
import {
baseAppSchema,
ConfigError,
ConfigManager,
ConfigValidationError,
createAppConfig,
getConfig,
getDatabaseConfig,
getLogConfig,
getQueueConfig,
getServiceConfig,
initializeAppConfig,
initializeServiceConfig,
isDevelopment,
isProduction,
isTest,
resetConfig,
} from '../src';
import { ConfigError, ConfigValidationError } from '../src/errors';
// Mock loader for testing
class MockLoader {
@ -172,21 +160,6 @@ describe('ConfigManager', () => {
expect(validated).toEqual({ name: 'test', port: 3000 });
});
it('should create typed getter', () => {
const schema = z.object({
name: z.string(),
port: z.number(),
});
const mockManager = new ConfigManager({
loaders: [new MockLoader({ name: 'test', port: 3000 })],
});
mockManager.initialize();
const getTypedConfig = mockManager.createTypedGetter(schema);
const config = getTypedConfig();
expect(config).toEqual({ name: 'test', port: 3000 });
});
it('should add environment if not present', () => {
const mockManager = new ConfigManager({
@ -199,68 +172,6 @@ describe('ConfigManager', () => {
});
});
describe('Config Service Functions', () => {
beforeEach(() => {
resetConfig();
});
it('should throw when getting config before initialization', () => {
expect(() => getConfig()).toThrow(ConfigError);
});
it('should validate config with schema', () => {
// Test that a valid config passes schema validation
const mockConfig = {
name: 'test-app',
version: '1.0.0',
environment: 'test' as const,
service: {
name: 'test-service',
baseUrl: 'http://localhost:3000',
port: 3000,
},
database: {
mongodb: {
uri: 'mongodb://localhost',
database: 'test-db',
},
postgres: {
host: 'localhost',
port: 5432,
database: 'test-db',
user: 'test-user',
password: 'test-pass',
},
questdb: {
host: 'localhost',
httpPort: 9000,
},
},
log: {
level: 'info' as const,
pretty: true,
},
queue: {
redis: { host: 'localhost', port: 6379 },
},
};
const manager = new ConfigManager({
loaders: [new MockLoader(mockConfig)],
});
// Should not throw when initializing with valid config
expect(() => manager.initialize(baseAppSchema)).not.toThrow();
// Verify key properties exist
const config = manager.get();
expect(config.name).toBe('test-app');
expect(config.version).toBe('1.0.0');
expect(config.environment).toBe('test');
expect(config.service.name).toBe('test-service');
expect(config.database.mongodb.uri).toBe('mongodb://localhost');
});
});
describe('Config Builders', () => {
it('should create app config with schema', () => {
@ -282,23 +193,16 @@ describe('Config Builders', () => {
version: z.number(),
});
const config = initializeAppConfig(schema, {
const configManager = createAppConfig(schema, {
loaders: [new MockLoader({ app: 'myapp', version: 1 })],
});
const config = configManager.initialize(schema);
expect(config).toEqual({ app: 'myapp', version: 1 });
});
});
describe('Environment Helpers', () => {
beforeEach(() => {
resetConfig();
});
afterEach(() => {
resetConfig();
});
describe('Environment Detection', () => {
it('should detect environments correctly in ConfigManager', () => {
// Test with different environments using mock configs
const envConfigs = [{ env: 'development' }, { env: 'production' }, { env: 'test' }];