fixed format issues
This commit is contained in:
parent
a700818a06
commit
08f713d98b
55 changed files with 5680 additions and 5533 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,10 +1,6 @@
|
|||
import { beforeEach, describe, expect, it } from 'bun:test';
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
baseAppSchema,
|
||||
ConfigManager,
|
||||
createAppConfig,
|
||||
} from '../src';
|
||||
import { baseAppSchema, ConfigManager, createAppConfig } from '../src';
|
||||
import { ConfigError, ConfigValidationError } from '../src/errors';
|
||||
|
||||
// Mock loader for testing
|
||||
|
|
@ -160,7 +156,6 @@ describe('ConfigManager', () => {
|
|||
expect(validated).toEqual({ name: 'test', port: 3000 });
|
||||
});
|
||||
|
||||
|
||||
it('should add environment if not present', () => {
|
||||
const mockManager = new ConfigManager({
|
||||
environment: 'test',
|
||||
|
|
@ -172,7 +167,6 @@ describe('ConfigManager', () => {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Config Builders', () => {
|
||||
it('should create app config with schema', () => {
|
||||
const schema = z.object({
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,12 +1,12 @@
|
|||
import { describe, it, expect, beforeEach, afterEach, mock } from 'bun:test';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import { FileLoader } from '../src/loaders/file.loader';
|
||||
import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test';
|
||||
import { ConfigLoaderError } from '../src/errors';
|
||||
import { FileLoader } from '../src/loaders/file.loader';
|
||||
|
||||
// Mock fs module
|
||||
mock.module('fs', () => ({
|
||||
existsSync: mock(() => false),
|
||||
readFileSync: mock(() => '')
|
||||
readFileSync: mock(() => ''),
|
||||
}));
|
||||
|
||||
describe('FileLoader', () => {
|
||||
|
|
@ -433,4 +433,4 @@ describe('FileLoader', () => {
|
|||
expect(result).toEqual(config);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
import { describe, it, expect } from 'bun:test';
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
baseConfigSchema,
|
||||
environmentSchema,
|
||||
serviceConfigSchema,
|
||||
loggingConfigSchema,
|
||||
queueConfigSchema,
|
||||
httpConfigSchema,
|
||||
webshareConfigSchema,
|
||||
browserConfigSchema,
|
||||
proxyConfigSchema,
|
||||
postgresConfigSchema,
|
||||
questdbConfigSchema,
|
||||
mongodbConfigSchema,
|
||||
dragonflyConfigSchema,
|
||||
databaseConfigSchema,
|
||||
baseProviderConfigSchema,
|
||||
browserConfigSchema,
|
||||
databaseConfigSchema,
|
||||
dragonflyConfigSchema,
|
||||
environmentSchema,
|
||||
eodProviderConfigSchema,
|
||||
httpConfigSchema,
|
||||
ibProviderConfigSchema,
|
||||
qmProviderConfigSchema,
|
||||
yahooProviderConfigSchema,
|
||||
webshareProviderConfigSchema,
|
||||
loggingConfigSchema,
|
||||
mongodbConfigSchema,
|
||||
postgresConfigSchema,
|
||||
providerConfigSchema,
|
||||
proxyConfigSchema,
|
||||
qmProviderConfigSchema,
|
||||
questdbConfigSchema,
|
||||
queueConfigSchema,
|
||||
serviceConfigSchema,
|
||||
webshareConfigSchema,
|
||||
webshareProviderConfigSchema,
|
||||
yahooProviderConfigSchema,
|
||||
} from '../src/schemas';
|
||||
|
||||
describe('Config Schemas', () => {
|
||||
|
|
@ -202,7 +202,7 @@ describe('Config Schemas', () => {
|
|||
describe('queueConfigSchema', () => {
|
||||
it('should accept minimal config with defaults', () => {
|
||||
const config = queueConfigSchema.parse({
|
||||
redis: {}, // redis is required, but its properties have defaults
|
||||
redis: {}, // redis is required, but its properties have defaults
|
||||
});
|
||||
expect(config).toEqual({
|
||||
enabled: true,
|
||||
|
|
@ -421,7 +421,7 @@ describe('Config Schemas', () => {
|
|||
// Empty strings are allowed by z.string() unless .min(1) is specified
|
||||
const serviceConfig = serviceConfigSchema.parse({ name: '', port: 3000 });
|
||||
expect(serviceConfig.name).toBe('');
|
||||
|
||||
|
||||
const baseConfig = baseConfigSchema.parse({ name: '' });
|
||||
expect(baseConfig.name).toBe('');
|
||||
});
|
||||
|
|
@ -493,19 +493,23 @@ describe('Config Schemas', () => {
|
|||
});
|
||||
|
||||
it('should validate poolSize range', () => {
|
||||
expect(() => postgresConfigSchema.parse({
|
||||
database: 'testdb',
|
||||
user: 'testuser',
|
||||
password: 'testpass',
|
||||
poolSize: 0,
|
||||
})).toThrow();
|
||||
|
||||
expect(() => postgresConfigSchema.parse({
|
||||
database: 'testdb',
|
||||
user: 'testuser',
|
||||
password: 'testpass',
|
||||
poolSize: 101,
|
||||
})).toThrow();
|
||||
expect(() =>
|
||||
postgresConfigSchema.parse({
|
||||
database: 'testdb',
|
||||
user: 'testuser',
|
||||
password: 'testpass',
|
||||
poolSize: 0,
|
||||
})
|
||||
).toThrow();
|
||||
|
||||
expect(() =>
|
||||
postgresConfigSchema.parse({
|
||||
database: 'testdb',
|
||||
user: 'testuser',
|
||||
password: 'testpass',
|
||||
poolSize: 101,
|
||||
})
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -574,24 +578,30 @@ describe('Config Schemas', () => {
|
|||
});
|
||||
|
||||
it('should validate URI format', () => {
|
||||
expect(() => mongodbConfigSchema.parse({
|
||||
uri: 'invalid-uri',
|
||||
database: 'testdb',
|
||||
})).toThrow();
|
||||
expect(() =>
|
||||
mongodbConfigSchema.parse({
|
||||
uri: 'invalid-uri',
|
||||
database: 'testdb',
|
||||
})
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('should validate poolSize range', () => {
|
||||
expect(() => mongodbConfigSchema.parse({
|
||||
uri: 'mongodb://localhost',
|
||||
database: 'testdb',
|
||||
poolSize: 0,
|
||||
})).toThrow();
|
||||
|
||||
expect(() => mongodbConfigSchema.parse({
|
||||
uri: 'mongodb://localhost',
|
||||
database: 'testdb',
|
||||
poolSize: 101,
|
||||
})).toThrow();
|
||||
expect(() =>
|
||||
mongodbConfigSchema.parse({
|
||||
uri: 'mongodb://localhost',
|
||||
database: 'testdb',
|
||||
poolSize: 0,
|
||||
})
|
||||
).toThrow();
|
||||
|
||||
expect(() =>
|
||||
mongodbConfigSchema.parse({
|
||||
uri: 'mongodb://localhost',
|
||||
database: 'testdb',
|
||||
poolSize: 101,
|
||||
})
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -645,7 +655,7 @@ describe('Config Schemas', () => {
|
|||
},
|
||||
dragonfly: {},
|
||||
});
|
||||
|
||||
|
||||
expect(config.postgres.host).toBe('localhost');
|
||||
expect(config.questdb.enabled).toBe(true);
|
||||
expect(config.mongodb.poolSize).toBe(10);
|
||||
|
|
@ -703,11 +713,13 @@ describe('Config Schemas', () => {
|
|||
});
|
||||
|
||||
it('should validate tier values', () => {
|
||||
expect(() => eodProviderConfigSchema.parse({
|
||||
name: 'eod',
|
||||
apiKey: 'test-key',
|
||||
tier: 'premium',
|
||||
})).toThrow();
|
||||
expect(() =>
|
||||
eodProviderConfigSchema.parse({
|
||||
name: 'eod',
|
||||
apiKey: 'test-key',
|
||||
tier: 'premium',
|
||||
})
|
||||
).toThrow();
|
||||
|
||||
const validTiers = ['free', 'fundamentals', 'all-in-one'];
|
||||
for (const tier of validTiers) {
|
||||
|
|
@ -759,10 +771,12 @@ describe('Config Schemas', () => {
|
|||
});
|
||||
|
||||
it('should validate marketDataType', () => {
|
||||
expect(() => ibProviderConfigSchema.parse({
|
||||
name: 'ib',
|
||||
marketDataType: 'realtime',
|
||||
})).toThrow();
|
||||
expect(() =>
|
||||
ibProviderConfigSchema.parse({
|
||||
name: 'ib',
|
||||
marketDataType: 'realtime',
|
||||
})
|
||||
).toThrow();
|
||||
|
||||
const validTypes = ['live', 'delayed', 'frozen'];
|
||||
for (const type of validTypes) {
|
||||
|
|
@ -777,9 +791,11 @@ describe('Config Schemas', () => {
|
|||
|
||||
describe('qmProviderConfigSchema', () => {
|
||||
it('should require all credentials', () => {
|
||||
expect(() => qmProviderConfigSchema.parse({
|
||||
name: 'qm',
|
||||
})).toThrow();
|
||||
expect(() =>
|
||||
qmProviderConfigSchema.parse({
|
||||
name: 'qm',
|
||||
})
|
||||
).toThrow();
|
||||
|
||||
const config = qmProviderConfigSchema.parse({
|
||||
name: 'qm',
|
||||
|
|
@ -885,7 +901,7 @@ describe('Config Schemas', () => {
|
|||
apiKey: 'ws-key',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
expect(config.eod?.tier).toBe('all-in-one');
|
||||
expect(config.ib?.gateway.port).toBe(7497);
|
||||
expect(config.qm?.username).toBe('user');
|
||||
|
|
@ -893,4 +909,4 @@ describe('Config Schemas', () => {
|
|||
expect(config.webshare?.apiKey).toBe('ws-key');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
SecretValue,
|
||||
secret,
|
||||
checkRequiredEnvVars,
|
||||
COMMON_SECRET_PATTERNS,
|
||||
createStrictSchema,
|
||||
formatValidationResult,
|
||||
isSecret,
|
||||
redactSecrets,
|
||||
isSecretEnvVar,
|
||||
wrapSecretEnvVars,
|
||||
mergeSchemas,
|
||||
redactSecrets,
|
||||
secret,
|
||||
secretSchema,
|
||||
secretStringSchema,
|
||||
COMMON_SECRET_PATTERNS,
|
||||
validateConfig,
|
||||
checkRequiredEnvVars,
|
||||
SecretValue,
|
||||
validateCompleteness,
|
||||
formatValidationResult,
|
||||
createStrictSchema,
|
||||
mergeSchemas,
|
||||
validateConfig,
|
||||
wrapSecretEnvVars,
|
||||
type ValidationResult,
|
||||
} from '../src';
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ describe('Config Utils', () => {
|
|||
it('should validate SecretValue instances', () => {
|
||||
const schema = secretSchema(z.string());
|
||||
const secretVal = new SecretValue('test');
|
||||
|
||||
|
||||
expect(() => schema.parse(secretVal)).not.toThrow();
|
||||
expect(() => schema.parse('test')).toThrow();
|
||||
expect(() => schema.parse(null)).toThrow();
|
||||
|
|
@ -132,7 +132,7 @@ describe('Config Utils', () => {
|
|||
};
|
||||
|
||||
const redacted = redactSecrets(obj, ['password', 'nested.apiKey']);
|
||||
|
||||
|
||||
expect(redacted).toEqual({
|
||||
username: 'admin',
|
||||
password: '***REDACTED***',
|
||||
|
|
@ -153,7 +153,7 @@ describe('Config Utils', () => {
|
|||
};
|
||||
|
||||
const redacted = redactSecrets(obj);
|
||||
|
||||
|
||||
expect(redacted).toEqual({
|
||||
normal: 'value',
|
||||
secret: 'MASKED',
|
||||
|
|
@ -172,7 +172,7 @@ describe('Config Utils', () => {
|
|||
};
|
||||
|
||||
const redacted = redactSecrets(obj);
|
||||
|
||||
|
||||
expect(redacted.items).toEqual([
|
||||
{ name: 'item1', secret: '***' },
|
||||
{ name: 'item2', secret: '***' },
|
||||
|
|
@ -187,7 +187,7 @@ describe('Config Utils', () => {
|
|||
};
|
||||
|
||||
const redacted = redactSecrets(obj);
|
||||
|
||||
|
||||
expect(redacted).toEqual({
|
||||
nullValue: null,
|
||||
undefinedValue: undefined,
|
||||
|
|
@ -240,13 +240,13 @@ describe('Config Utils', () => {
|
|||
};
|
||||
|
||||
const wrapped = wrapSecretEnvVars(env);
|
||||
|
||||
|
||||
expect(wrapped.USERNAME).toBe('admin');
|
||||
expect(wrapped.PORT).toBe('3000');
|
||||
|
||||
|
||||
expect(isSecret(wrapped.PASSWORD)).toBe(true);
|
||||
expect(isSecret(wrapped.API_KEY)).toBe(true);
|
||||
|
||||
|
||||
const passwordSecret = wrapped.PASSWORD as SecretValue;
|
||||
expect(passwordSecret.reveal('test')).toBe('secret123');
|
||||
expect(passwordSecret.toString()).toBe('***PASSWORD***');
|
||||
|
|
@ -259,7 +259,7 @@ describe('Config Utils', () => {
|
|||
};
|
||||
|
||||
const wrapped = wrapSecretEnvVars(env);
|
||||
|
||||
|
||||
expect(wrapped.PASSWORD).toBeUndefined();
|
||||
expect(wrapped.USERNAME).toBe('admin');
|
||||
});
|
||||
|
|
@ -443,9 +443,7 @@ describe('Config Utils', () => {
|
|||
it('should format warnings', () => {
|
||||
const result: ValidationResult = {
|
||||
valid: true,
|
||||
warnings: [
|
||||
{ path: 'deprecated.feature', message: 'This feature is deprecated' },
|
||||
],
|
||||
warnings: [{ path: 'deprecated.feature', message: 'This feature is deprecated' }],
|
||||
};
|
||||
|
||||
const formatted = formatValidationResult(result);
|
||||
|
|
@ -499,7 +497,7 @@ describe('Config Utils', () => {
|
|||
const schema2 = z.object({ b: z.number(), shared: z.string() });
|
||||
|
||||
const merged = mergeSchemas(schema1, schema2);
|
||||
|
||||
|
||||
// Both schemas require 'shared' to be a string
|
||||
expect(() => merged.parse({ a: 'test', b: 123, shared: 'value' })).not.toThrow();
|
||||
expect(() => merged.parse({ a: 'test', b: 123, shared: 123 })).toThrow();
|
||||
|
|
@ -510,10 +508,10 @@ describe('Config Utils', () => {
|
|||
it('should be an array of RegExp', () => {
|
||||
expect(Array.isArray(COMMON_SECRET_PATTERNS)).toBe(true);
|
||||
expect(COMMON_SECRET_PATTERNS.length).toBeGreaterThan(0);
|
||||
|
||||
|
||||
for (const pattern of COMMON_SECRET_PATTERNS) {
|
||||
expect(pattern).toBeInstanceOf(RegExp);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue