-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathconfig.test.mjs
More file actions
103 lines (74 loc) · 2.88 KB
/
config.test.mjs
File metadata and controls
103 lines (74 loc) · 2.88 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import assert from 'node:assert';
import process from 'node:process';
import { describe, it, beforeEach, afterEach } from 'node:test';
import { getConfig } from '../src/config.mjs';
describe('Config', () => {
let originalEnv;
let originalArgv;
beforeEach(() => {
// Save original environment and argv
originalEnv = { ...process.env };
originalArgv = [...process.argv];
});
afterEach(() => {
// Restore original environment and argv
process.env = originalEnv;
process.argv = originalArgv;
});
describe('getConfig', () => {
it('should return empty meeting group when no argument provided', () => {
process.argv = ['node', 'script.mjs'];
const config = getConfig();
assert.strictEqual(config.meetingGroup, undefined);
});
it('should use command line argument for meeting group', () => {
process.argv = ['node', 'script.mjs', 'build'];
const config = getConfig();
assert.strictEqual(config.meetingGroup, 'build');
});
it('should read GitHub token from environment', () => {
process.env.GITHUB_TOKEN = 'test_token';
const config = getConfig();
assert.strictEqual(config.githubToken, 'test_token');
});
it('should read Google API Key config from environment', () => {
process.env.GOOGLE_API_KEY = 'test_google_api_key_123';
const config = getConfig();
assert.strictEqual(config.google.apiKey, 'test_google_api_key_123');
});
it('should handle missing Google API Key gracefully', () => {
delete process.env.GOOGLE_API_KEY;
const config = getConfig();
assert.strictEqual(config.google.apiKey, undefined);
});
it('should read HackMD config from environment', () => {
process.env.HACKMD_API_TOKEN = 'hackmd_token';
const config = getConfig();
assert.strictEqual(config.hackmd.apiToken, 'hackmd_token');
});
it('should handle undefined environment variables gracefully', () => {
// Clear all relevant env vars
delete process.env.GITHUB_TOKEN;
delete process.env.HACKMD_API_TOKEN;
delete process.env.GOOGLE_CLIENT_ID;
const config = getConfig();
assert.strictEqual(config.githubToken, undefined);
assert.strictEqual(config.hackmd.apiToken, undefined);
assert.strictEqual(config.google.clientId, undefined);
});
it('should contain all required config sections', () => {
const config = getConfig();
assert.ok('meetingGroup' in config);
assert.ok('githubToken' in config);
assert.ok('google' in config);
assert.ok('hackmd' in config);
assert.ok('directories' in config);
});
it('should contain all required directory paths', () => {
const config = getConfig();
assert.ok('config' in config.directories);
assert.ok('output' in config.directories);
assert.ok('templates' in config.directories);
});
});
});