forked from XeroAPI/xero-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
items.integration.tests.ts
70 lines (56 loc) · 2.12 KB
/
items.integration.tests.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
import { ItemsResponse } from '../AccountingAPI-responses';
import { AccountingAPIClient } from '../AccountingAPIClient';
import { getOrCreateItemId } from './helpers/entityId.helpers';
import { getPrivateConfig, setJestTimeout } from './helpers/integration.helpers';
describe('/items', () => {
let xero: AccountingAPIClient;
let idsToArchive: string[] = [];
beforeAll(() => {
setJestTimeout();
const config = getPrivateConfig('1');
xero = new AccountingAPIClient(config);
});
it('create single', async () => {
const response = await xero.items.create({
Code: 'DevX-was-here'
});
collectIdsToArchive(response);
expect(response.Items.length).toBe(1);
expect(response.Items[0].Code).toEqual('DevX-was-here');
});
it('get single', async () => {
const response = await xero.items.get({ ItemID: await getOrCreateItemId(xero) });
expect(response).toBeDefined();
expect(response.Id).toBeTruthy();
expect(response.Items.length).toBe(1);
expect(response.Items[0].ItemID).toBeTruthy();
});
it('get all', async () => {
const response = await xero.items.get();
expect(response).toBeDefined();
expect(response.Id).toBeTruthy();
expect(response.Items.length).toBeGreaterThan(0);
expect(response.Items[0].ItemID).toBeTruthy();
});
// it('get history', async () => {
// const response = await xero.items.history.get({ ItemID: await getOrCreateItemId(xero)});
// expect(response.HistoryRecords[0]).toBeDefined();
// });
it('update', async () => {
const response = await xero.items.update({
ItemID: await getOrCreateItemId(xero),
Code: 'Another-code'
});
expect(response).toBeDefined();
expect(response.Id).toBeTruthy();
expect(response.Items.length).toBe(1);
expect(response.Items[0].ItemID).toBeTruthy();
expect(response.Items[0].Code).toEqual('Another-code');
});
afterAll(async () => {
await Promise.all(idsToArchive.map((id) => xero.items.delete({ ItemID: id })));
});
function collectIdsToArchive(response: ItemsResponse) {
idsToArchive = idsToArchive.concat(response.Items.map((item) => item.ItemID));
}
});