-
Notifications
You must be signed in to change notification settings - Fork 6
/
set.spec.ts
114 lines (102 loc) · 2.99 KB
/
set.spec.ts
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
114
jest.mock('../../lib/config/config');
jest.mock('../../hooks/analytics/analytics');
jest.mock('../../hooks/prerun/prerun');
jest.mock('../../lib/platform/authenticatedClient');
import {mocked} from 'ts-jest/utils';
import {Config} from '../../lib/config/config';
import {test} from '@oclif/test';
import {AuthenticatedClient} from '../../lib/platform/authenticatedClient';
const mockedConfig = mocked(Config);
const mockedClient = mocked(AuthenticatedClient);
describe('config:set', () => {
const mockSet = jest.fn();
const mockGetHasAccessToOrg = jest.fn();
mockedConfig.mockImplementation(
() =>
({
set: mockSet,
} as unknown as Config)
);
mockedClient.mockImplementation(
() =>
({
getUserHasAccessToOrg: mockGetHasAccessToOrg,
} as unknown as AuthenticatedClient)
);
test
.stdout()
.command(['config:set'])
.it(
'allows to call set without any flags and should not modify configuration',
() => {
expect(mockSet).not.toHaveBeenCalled();
}
);
['dev', 'qa', 'prod', 'hipaa'].forEach((environment) => {
test
.stdout()
.command(['config:set', '-e', environment])
.it(`allows to modify environment ${environment}`, () => {
expect(mockSet).toHaveBeenCalledWith('environment', environment);
});
});
test
.stdout()
.command(['config:set', '-e', 'foo'])
.catch(/Expected --environment=foo/)
.it('fails when trying to set an invalid environment', () => {
expect(mockSet).not.toHaveBeenCalled();
});
[
'us-east-1',
'eu-west-1',
'eu-west-3',
'ap-southeast-2',
'us-west-2',
].forEach((region) => {
test
.stdout()
.command(['config:set', '-r', region])
.it(`allows to modify region ${region}`, () => {
expect(mockSet).toHaveBeenCalledWith('region', region);
});
});
test
.stdout()
.command(['config:set', '-r', 'foo'])
.catch(/Expected --region=foo/)
.it('fails when trying to set an invalid region', () => {
expect(mockSet).not.toHaveBeenCalled();
});
test
.stdout()
.do(() => {
mockGetHasAccessToOrg.mockReturnValueOnce(Promise.resolve(true));
})
.command(['config:set', '-o', 'the_org'])
.it(
'allows to modify the organization of the user has access to it',
() => {
expect(mockSet).toHaveBeenCalledWith('organization', 'the_org');
}
);
test
.stdout()
.do(() => {
mockGetHasAccessToOrg.mockReturnValueOnce(Promise.resolve(false));
})
.command(['config:set', '-o', 'the_org'])
.catch(/do not have access to organization the_org/)
.it(
'fails when trying to set to an invalid organzation the user does not have access to',
() => {
expect(mockSet).not.toHaveBeenCalled();
}
);
test
.stdout()
.command(['config:set', '-a', 'y'])
.it('allows to modify the analytics configuration', () => {
expect(mockSet).toHaveBeenCalledWith('analyticsEnabled', true);
});
});