-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathconfig.spec.ts
More file actions
113 lines (93 loc) · 3.58 KB
/
Copy pathconfig.spec.ts
File metadata and controls
113 lines (93 loc) · 3.58 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
104
105
106
107
108
109
110
111
112
113
import { getClientConfig, getRequiredOption, getApiKey } from '../lib/commons/config';
import {
ReportPortalRequiredOptionError,
ReportPortalValidationError,
} from '../lib/commons/errors';
describe('Config commons test suite', () => {
describe('getRequiredOption', () => {
it('should return option if it presented in options and has value', () => {
const option = getRequiredOption({ project: 1 }, 'project');
expect(option).toBe(1);
});
it('should throw ReportPortalRequiredOptionError in case of empty option', () => {
let error;
try {
getRequiredOption({ project: undefined }, 'project');
} catch (e) {
error = e;
}
expect(error).toBeDefined();
expect(error).toBeInstanceOf(ReportPortalRequiredOptionError);
});
it('should throw ReportPortalRequiredOptionError in case of option not present in options', () => {
let error;
try {
getRequiredOption({ other: 1 } as any, 'project');
} catch (e) {
error = e;
}
expect(error).toBeDefined();
expect(error).toBeInstanceOf(ReportPortalRequiredOptionError);
});
});
describe('getApiKey', () => {
it('should return apiKey if it presented in options and has value', () => {
const apiKey = getApiKey({ apiKey: '1' });
expect(apiKey).toBe('1');
});
it('should return apiKey if it provided in options via deprecated token option', () => {
const apiKey = getApiKey({ token: '1' });
expect(apiKey).toBe('1');
});
it('should print warning to console if deprecated token option used', () => {
jest.spyOn(console, 'warn').mockImplementation();
getApiKey({ token: '1' });
expect(console.warn).toHaveBeenCalledWith(
`Option 'token' is deprecated. Use 'apiKey' instead.`,
);
});
it('should throw ReportPortalRequiredOptionError in case of no one option present', () => {
let error;
try {
getApiKey({});
} catch (e) {
error = e;
}
expect(error).toBeDefined();
expect(error).toBeInstanceOf(ReportPortalRequiredOptionError);
});
});
describe('getClientConfig', () => {
it('should print ReportPortalValidationError error to the console in case of options is not an object type', () => {
jest.spyOn(console, 'dir').mockImplementation();
getClientConfig('options' as any);
expect(console.dir).toHaveBeenCalledWith(
new ReportPortalValidationError('`options` must be an object.'),
);
});
it('should print ReportPortalRequiredOptionError to the console in case of "endpoint" option missed', () => {
jest.spyOn(console, 'dir').mockImplementation();
getClientConfig({
apiKey: '123',
project: 'prj',
});
expect(console.dir).toHaveBeenCalledWith(new ReportPortalRequiredOptionError('endpoint'));
});
it('should print ReportPortalRequiredOptionError to the console in case of "project" option missed', () => {
jest.spyOn(console, 'dir').mockImplementation();
getClientConfig({
apiKey: '123',
endpoint: 'https://abc.com',
});
expect(console.dir).toHaveBeenCalledWith(new ReportPortalRequiredOptionError('project'));
});
it('should print ReportPortalRequiredOptionError to the console in case of "apiKey" option missed', () => {
jest.spyOn(console, 'dir').mockImplementation();
getClientConfig({
project: 'prj',
endpoint: 'https://abc.com',
});
expect(console.dir).toHaveBeenCalledWith(new ReportPortalRequiredOptionError('apiKey'));
});
});
});