forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.spec.ts
More file actions
58 lines (50 loc) · 1.68 KB
/
Copy pathenv.spec.ts
File metadata and controls
58 lines (50 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { envSchema } from '../env';
describe('Environment Validation', () => {
it('should validate valid environment variables', () => {
const validEnv = {
NODE_ENV: 'development',
DATABASE_URL: 'postgresql://user:pass@localhost:5432/db',
JWT_SECRET: 'a'.repeat(32),
ISSUER_PUBLIC: 'GABC123',
ISSUER_SECRET: 'SABC123',
};
const result = envSchema.safeParse(validEnv);
expect(result.success).toBe(true);
});
it('should reject missing required variables', () => {
const invalidEnv = {
NODE_ENV: 'development',
};
const result = envSchema.safeParse(invalidEnv);
expect(result.success).toBe(false);
});
it('should reject invalid JWT_SECRET length', () => {
const invalidEnv = {
NODE_ENV: 'development',
DATABASE_URL: 'postgresql://user:pass@localhost:5432/db',
JWT_SECRET: 'short',
ISSUER_PUBLIC: 'GABC123',
ISSUER_SECRET: 'SABC123',
};
const result = envSchema.safeParse(invalidEnv);
expect(result.success).toBe(false);
if (!result.success) {
expect(result.error.errors.some(e => e.path.includes('JWT_SECRET'))).toBe(true);
}
});
it('should apply defaults for optional variables', () => {
const minimalEnv = {
DATABASE_URL: 'postgresql://user:pass@localhost:5432/db',
JWT_SECRET: 'a'.repeat(32),
ISSUER_PUBLIC: 'GABC123',
ISSUER_SECRET: 'SABC123',
};
const result = envSchema.safeParse(minimalEnv);
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.NODE_ENV).toBe('development');
expect(result.data.PORT).toBe(3000);
expect(result.data.STELLAR_NETWORK).toBe('testnet');
}
});
});