-
Notifications
You must be signed in to change notification settings - Fork 6
/
monitor.spec.ts
89 lines (78 loc) · 2.38 KB
/
monitor.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
jest.mock('../../../lib/config/config');
jest.mock('../../../hooks/analytics/analytics');
jest.mock('../../../hooks/prerun/prerun');
jest.mock('../../../lib/platform/authenticatedClient');
import {AuthenticatedClient} from '../../../lib/platform/authenticatedClient';
import {Config} from '../../../lib/config/config';
import {mocked} from 'jest-mock';
import {ResourceSnapshotsReportType} from '@coveord/platform-client';
import {test} from '@oclif/test';
import {getDummySnapshotModel} from '../../../__stub__/resourceSnapshotsModel';
import {getSuccessReport} from '../../../__stub__/resourceSnapshotsReportModel';
const mockedAuthenticatedClient = mocked(AuthenticatedClient, true);
const mockedConfig = mocked(Config);
const mockedConfigGet = jest.fn();
const mockedGetClient = jest.fn();
const mockedGetSnapshot = jest.fn();
const doMockConfig = () => {
mockedConfigGet.mockReturnValue(
Promise.resolve({
region: 'us',
organization: 'default-org',
environment: 'prod',
})
);
mockedConfig.mockImplementation(
() =>
({
get: mockedConfigGet,
} as unknown as Config)
);
};
const doMockAuthenticatedClient = () => {
mockedGetClient.mockImplementation(() =>
Promise.resolve({
resourceSnapshot: {
get: mockedGetSnapshot,
},
})
);
mockedAuthenticatedClient.prototype.getClient.mockImplementation(
mockedGetClient
);
};
describe('org:resources:monitor', () => {
beforeAll(() => {
doMockConfig();
doMockAuthenticatedClient();
mockedGetSnapshot.mockResolvedValue(
getDummySnapshotModel('default-org', 'my-snapshot', [
getSuccessReport('my-snapshot', ResourceSnapshotsReportType.Apply),
])
);
});
test
.stdout()
.stderr()
.command(['org:resources:monitor'])
.catch(/Missing 1 required arg/)
.it('requires snapshotId name argument');
test
.stdout()
.stderr()
.command(['org:resources:monitor', 'my-snapshot'])
.it('should work with default connected org', () => {
expect(mockedGetClient).toHaveBeenCalledWith({
organization: 'default-org',
});
});
test
.stdout()
.stderr()
.command(['org:resources:monitor', 'other-snapshot', '-t', 'different-org'])
.it('should work with default connected org', () => {
expect(mockedGetClient).toHaveBeenCalledWith({
organization: 'different-org',
});
});
});