-
Notifications
You must be signed in to change notification settings - Fork 6
/
create.spec.ts
87 lines (78 loc) · 2.32 KB
/
create.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
jest.mock('../../lib/config/config');
jest.mock('../../hooks/analytics/analytics');
jest.mock('../../hooks/prerun/prerun');
jest.mock('../../lib/platform/authenticatedClient');
import {mocked} from 'jest-mock';
import {test} from '@oclif/test';
import {AuthenticatedClient} from '../../lib/platform/authenticatedClient';
import {OrganizationCreationOrigin} from '@coveord/platform-client';
import {Config} from '../../lib/config/config';
const mockedAuthenticatedClient = mocked(AuthenticatedClient, true);
const mockedConfig = mocked(Config, true);
const mockedCreate = jest.fn();
const mockConfigSet = jest.fn();
const mockConfigGet = jest.fn().mockResolvedValue({
organization: 'foo',
});
const mockAuthenticatedClient = () => {
mockedAuthenticatedClient.mockImplementation(
() =>
({
getClient: () =>
Promise.resolve({organization: {create: mockedCreate}}),
} as unknown as AuthenticatedClient)
);
};
const mockConfig = () => {
mockedConfig.mockImplementation(
() =>
({
set: mockConfigSet,
get: mockConfigGet,
} as unknown as Config)
);
};
describe('org:create', () => {
beforeAll(() => {
mockAuthenticatedClient();
mockConfig();
mockedCreate.mockReturnValue({id: 'mytestorg12345'});
});
test
.stdout()
.stderr()
.command(['org:create', 'my-test-org'])
.it('should create an organization with the right parameters', () => {
expect(mockedCreate).toHaveBeenCalledWith({
creationOrigin: OrganizationCreationOrigin.CLI,
name: 'my-test-org',
organizationTemplate: 'Developer',
});
});
test
.stdout()
.stderr()
.command(['org:create', 'my-test-org'])
.it('should log the newly created org id', (ctx) => {
expect(ctx.stderr).toContain(
'Organization mytestorg12345 successfully created.'
);
});
test
.stdout()
.stderr()
.command(['org:create', 'my-test-org'])
.it('should set the newly created org as the default one', () => {
expect(mockConfigSet).toHaveBeenCalledWith(
'organization',
'mytestorg12345'
);
});
test
.stdout()
.stderr()
.command(['org:create', 'my-test-org', '--no-setDefaultOrganization'])
.it('should not set default org', () => {
expect(mockConfigSet).toHaveBeenCalledTimes(0);
});
});