-
Notifications
You must be signed in to change notification settings - Fork 6
/
list.spec.ts
77 lines (70 loc) · 2.19 KB
/
list.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
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 {test} from '@oclif/test';
import {AuthenticatedClient} from '../../lib/platform/authenticatedClient';
import {OrganizationModel} from '@coveord/platform-client';
const mockedClient = mocked(AuthenticatedClient);
const mockGetOrgs = jest.fn().mockReturnValue(Promise.resolve([]));
describe('org:list', () => {
const createMockOrgDefinition = (id: string): OrganizationModel => ({
createdDate: new Date().getTime(),
displayName: `${id}_displayName`,
id,
owner: {email: `${id}_owner_email`},
publicContentOnly: false,
readOnly: false,
type: 'TRIAL',
});
mockedClient.mockImplementation(
() =>
({
getAllOrgsUserHasAccessTo: mockGetOrgs,
} as unknown as AuthenticatedClient)
);
test
.stdout()
.command(['org:list'])
.it('works when the user has access to no org', (ctx) => {
expect(ctx.stdout).toContain(
'You do not have access to any organization'
);
});
test
.do(() => {
mockGetOrgs.mockReturnValueOnce(
Promise.resolve([
createMockOrgDefinition('first_org'),
createMockOrgDefinition('second_org'),
])
);
})
.stdout()
.command(['org:list'])
.it('works when the user has access to a list of org', (ctx) => {
expect(ctx.stdout).toContain('first_org');
expect(ctx.stdout).toContain('second_org');
});
test
.do(() => {
mockGetOrgs.mockReturnValueOnce(
Promise.resolve([
createMockOrgDefinition('first_org'),
createMockOrgDefinition('second_org'),
])
);
})
.stdout()
.command(['org:list', '-x'])
.it(
'works when the user has access to a list of org with extended details',
(ctx) => {
expect(ctx.stdout).toContain('first_org_owner_email');
expect(ctx.stdout).toContain('first_org_displayName');
expect(ctx.stdout).toContain('second_org_owner_email');
expect(ctx.stdout).toContain('second_org_displayName');
}
);
});