/
Nexus.spec.ts
37 lines (34 loc) · 1.23 KB
/
Nexus.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
import { resetMocks, mock, mockResponses } from 'jest-fetch-mock';
import Nexus from '..';
import { mockOrgResponse, mockListProjectResponse } from '../__mocks__/helpers';
import Organization from '../Organization';
import { PaginatedList } from '../utils/types';
const nexus = new Nexus({ environment: 'http://example.com' });
describe('Nexus class', () => {
it('should create a Nexus instance', () => {
expect(nexus).toBeInstanceOf(Nexus);
});
describe('get an Org', () => {
afterEach(() => {
resetMocks();
});
it('should return an organisation', async () => {
mockResponses([JSON.stringify(mockOrgResponse)]);
const org: Organization = await nexus.getOrganization('myorg');
expect(mock.calls.length).toBe(1);
expect(org).toBeInstanceOf(Organization);
expect(org.label).toEqual('myorg');
});
});
describe('list a list of Org', () => {
afterEach(() => {
resetMocks();
});
it('should return a list of organisations', async () => {
mockResponses([JSON.stringify(mockListProjectResponse)]);
const orgs: PaginatedList<Organization> = await nexus.listOrganizations();
expect(mock.calls.length).toBe(1);
expect(orgs.total).toEqual(1);
});
});
});