-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathConsumer.api.test.js
104 lines (88 loc) · 3.08 KB
/
Consumer.api.test.js
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
import ConsumerApi from '../Consumer.api';
import {
CONSUMER_DETAILS_URL,
CONSUMER_ADDRESSES_URL,
AUTHORISATION_HEADER_NAME,
ACCEPT_TENANT_HEADER_NAME
} from '../../../constants';
import {
baseUrl,
token,
consumerUpdateBody
} from '../../../../test-utils/setup';
let apiProvider;
let httpClientMock;
let cookiesMock;
const cookiesSetSpy = jest.fn();
const httpGetSpy = jest.fn();
const httpPatchSpy = jest.fn();
describe('ConsumerApi Provider', () => {
beforeEach(() => {
httpClientMock = {
get: httpGetSpy,
patch: httpPatchSpy
};
cookiesMock = {
set: cookiesSetSpy
};
apiProvider = new ConsumerApi({ httpClient: httpClientMock, cookies: cookiesMock, baseUrl });
});
afterEach(() => {
jest.clearAllMocks();
});
describe('When creating a new instance', () => {
it('should not throw error when instance is created with valid parameters', () => {
// Act
const createInstance = () => new ConsumerApi({
httpClient: {}
});
// Assert
let instance;
expect(() => { instance = createInstance(); }).not.toThrowError();
expect(instance).toBeDefined();
});
});
describe('When calling `getConsumerDetails`', () => {
it('should send the correct parameters', async () => {
// Arrange
const expectedUri = `${baseUrl}/${CONSUMER_DETAILS_URL}`;
const expectedHeaders = {
[AUTHORISATION_HEADER_NAME]: `Bearer ${token}`,
[ACCEPT_TENANT_HEADER_NAME]: 'uk'
};
// Act
await apiProvider.getConsumerDetails(token);
// Assert
expect(httpGetSpy).toHaveBeenCalledWith(expectedUri, expectedHeaders);
});
});
describe('When calling `getConsumerAddresses`', () => {
it('should send the correct parameters', async () => {
// Arrange
const expectedUri = `${baseUrl}/${CONSUMER_ADDRESSES_URL}`;
const expectedHeaders = {
[AUTHORISATION_HEADER_NAME]: `Bearer ${token}`,
[ACCEPT_TENANT_HEADER_NAME]: 'uk'
};
// Act
await apiProvider.getConsumerAddresses(token);
// Assert
expect(httpGetSpy).toHaveBeenCalledWith(expectedUri, expectedHeaders);
});
});
describe('When calling `patchConsumer`', () => {
it('should send the correct parameters', async () => {
// Arrange
const expectedUri = `${baseUrl}/${CONSUMER_DETAILS_URL}`;
const expectedBody = consumerUpdateBody;
const expectedHeaders = {
[AUTHORISATION_HEADER_NAME]: `Bearer ${token}`,
[ACCEPT_TENANT_HEADER_NAME]: 'uk'
};
// Act
await apiProvider.patchConsumer(token, consumerUpdateBody);
// Assert
expect(httpPatchSpy).toHaveBeenCalledWith(expectedUri, expectedBody, expectedHeaders);
});
});
});