Skip to content

Commit efe84d6

Browse files
Add tests for system.ts
1 parent 984b9ab commit efe84d6

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { ApplicationError } from '@openops/shared';
2+
import {
3+
AppSystemProp,
4+
SharedSystemProp,
5+
system,
6+
} from '../../src/lib/system';
7+
8+
describe('system configuration helpers', () => {
9+
const originalEnv = process.env;
10+
11+
beforeEach(() => {
12+
process.env = { ...originalEnv };
13+
Object.keys(process.env).forEach((key) => {
14+
if (key.startsWith('OPS_')) {
15+
delete process.env[key];
16+
}
17+
});
18+
});
19+
20+
afterAll(() => {
21+
process.env = originalEnv;
22+
});
23+
24+
it('returns environment values through getOrThrow', () => {
25+
process.env['OPS_API_KEY'] = 'super-secret';
26+
27+
expect(system.getOrThrow(AppSystemProp.API_KEY)).toBe('super-secret');
28+
});
29+
30+
it('falls back to default values when env is missing', () => {
31+
expect(system.getOrThrow(SharedSystemProp.LOG_LEVEL)).toBe('info');
32+
});
33+
34+
it('throws an ApplicationError when a required value is missing', () => {
35+
expect(() => system.getOrThrow(AppSystemProp.API_KEY)).toThrow(
36+
ApplicationError,
37+
);
38+
});
39+
40+
it('parses numeric values and exposes helpers', () => {
41+
process.env['OPS_MAX_CONCURRENT_JOBS_PER_PROJECT'] = '200';
42+
process.env['OPS_LOG_PRETTY'] = 'true';
43+
44+
expect(
45+
system.getNumberOrThrow(AppSystemProp.MAX_CONCURRENT_JOBS_PER_PROJECT),
46+
).toBe(200);
47+
expect(system.getBoolean(SharedSystemProp.LOG_PRETTY)).toBe(true);
48+
});
49+
50+
it('parses comma separated lists and updates configuration hash when values change', () => {
51+
const baseHash = system.calculateConfigurationHash();
52+
53+
process.env['OPS_ALLOWED_DOMAINS'] = 'openops.com, example.com';
54+
process.env['OPS_COMPONENT'] = 'api';
55+
56+
expect(system.getList(AppSystemProp.ALLOWED_DOMAINS)).toEqual([
57+
'openops.com',
58+
'example.com',
59+
]);
60+
61+
const updatedHash = system.calculateConfigurationHash();
62+
expect(updatedHash).not.toBe(baseHash);
63+
});
64+
65+
it('returns null for invalid numeric values', () => {
66+
process.env['OPS_MAX_CONCURRENT_JOBS_PER_PROJECT'] = 'not-a-number';
67+
68+
expect(
69+
system.getNumber(AppSystemProp.MAX_CONCURRENT_JOBS_PER_PROJECT),
70+
).toBeNull();
71+
});
72+
});

0 commit comments

Comments
 (0)