forked from firefox-devtools/profiler-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.test.js
70 lines (63 loc) · 2.33 KB
/
config.test.js
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import fs from 'fs';
import { config, loadConfigForTestsOnly as loadConfig } from '../../src/config';
describe('config.js', () => {
it('returns default values', () => {
expect(config).toEqual({
env: 'test',
httpPort: 5252,
gcsBucket: 'profile-store',
googleAuthenticationFilePath: '',
jwtSecret: 'secret',
bitlyToken: 'FAKE_TOKEN_FOR_TESTS',
});
expect(loadConfig()).toEqual({
env: 'test',
httpPort: 5252,
gcsBucket: 'profile-store',
googleAuthenticationFilePath: '',
jwtSecret: 'secret',
bitlyToken: 'FAKE_TOKEN_FOR_TESTS',
});
});
it('configures other values from environment variables', () => {
process.env.PORT = '12345';
expect(loadConfig().httpPort).toEqual(12345);
delete process.env.PORT;
});
it(`when not in tests throws if there's no jwt secret specified`, () => {
process.env.NODE_ENV = 'production';
expect(() => loadConfig()).toThrow();
process.env.NODE_ENV = 'test';
});
it('accepts mocked google authentication paths', () => {
process.env.GCS_AUTHENTICATION_PATH = 'MOCKED';
expect(loadConfig().googleAuthenticationFilePath).toEqual('MOCKED');
delete process.env.GCS_AUTHENTICATION_PATH;
});
it('accepts valid google authentication paths', () => {
const filePath = '/path/to/file';
jest.spyOn(fs, 'accessSync').mockReturnValue();
process.env.GCS_AUTHENTICATION_PATH = filePath;
expect(loadConfig().googleAuthenticationFilePath).toEqual(filePath);
delete process.env.GCS_AUTHENTICATION_PATH;
});
it('rejects google authentication paths that are not readable', () => {
const filePath = '/path/to/file';
jest.spyOn(process.stdout, 'write').mockImplementation(() => {});
jest.spyOn(fs, 'accessSync').mockImplementation(() => {
throw new Error();
});
process.env.GCS_AUTHENTICATION_PATH = filePath;
expect(() => loadConfig()).toThrow(
'The authentication file is missing or not readable.'
);
expect(process.stdout.write).toHaveBeenCalledWith(
expect.stringContaining('CRITICAL')
);
delete process.env.GCS_AUTHENTICATION_PATH;
});
});