-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.test.ts
More file actions
43 lines (38 loc) · 1.55 KB
/
Copy pathconfig.test.ts
File metadata and controls
43 lines (38 loc) · 1.55 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
import { describe, expect, it } from 'vitest';
import { ConfigError, loadApiBaseUrl, loadAuthConfig } from '../src/lib/config';
const FULL_ENV = {
PUBLIC_COGNITO_DOMAIN: 'openjobradar-dev.auth.us-east-1.amazoncognito.com',
PUBLIC_COGNITO_CLIENT_ID: 'client-abc',
PUBLIC_REDIRECT_URI: 'http://localhost:4321/callback',
PUBLIC_LOGOUT_URI: 'http://localhost:4321/',
PUBLIC_API_BASE_URL: 'https://api.example.com',
} as const;
describe('loadAuthConfig', () => {
it('maps every PUBLIC_ env var to the AuthConfig shape', () => {
const config = loadAuthConfig(FULL_ENV);
expect(config).toEqual({
domain: FULL_ENV.PUBLIC_COGNITO_DOMAIN,
clientId: FULL_ENV.PUBLIC_COGNITO_CLIENT_ID,
redirectUri: FULL_ENV.PUBLIC_REDIRECT_URI,
logoutUri: FULL_ENV.PUBLIC_LOGOUT_URI,
});
});
it.each(['PUBLIC_COGNITO_DOMAIN', 'PUBLIC_COGNITO_CLIENT_ID', 'PUBLIC_REDIRECT_URI', 'PUBLIC_LOGOUT_URI'] as const)(
'fails loudly, not silently, when %s is missing',
(missingKey) => {
const env = { ...FULL_ENV, [missingKey]: '' };
expect(() => loadAuthConfig(env)).toThrow(ConfigError);
expect(() => loadAuthConfig(env)).toThrow(new RegExp(missingKey));
},
);
});
describe('loadApiBaseUrl', () => {
it('strips a trailing slash', () => {
expect(loadApiBaseUrl({ ...FULL_ENV, PUBLIC_API_BASE_URL: 'https://api.example.com/' })).toBe(
'https://api.example.com',
);
});
it('fails loudly when missing', () => {
expect(() => loadApiBaseUrl({ ...FULL_ENV, PUBLIC_API_BASE_URL: '' })).toThrow(ConfigError);
});
});