forked from XeroAPI/xero-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expenseclaims.integration.tests.ts
78 lines (62 loc) · 2.45 KB
/
expenseclaims.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
71
72
73
74
75
76
77
78
import { ExpenseClaimsResponse } from '../AccountingAPI-responses';
import { AccountingAPIClient } from '../AccountingAPIClient';
import { getOrCreateExpenseClaimId } from './helpers/entityId.helpers';
import { getPrivateConfig, setJestTimeout } from './helpers/integration.helpers';
describe('/expenseclaims', () => {
let xero: AccountingAPIClient;
let idsToArchive: string[] = [];
beforeAll(() => {
setJestTimeout();
const config = getPrivateConfig();
xero = new AccountingAPIClient(config);
});
it('create single', async () => {
const response = await xero.expenseClaims.create({
AmountDue: 123
});
collectIdsToArchive(response);
expect(response.ExpenseClaims.length).toBe(1);
expect(response.ExpenseClaims[0].AmountDue).toEqual(123);
});
it('get single', async () => {
const response = await xero.expenseClaims.get({ ExpenseClaimID: await getOrCreateExpenseClaimId(xero) });
expect(response).toBeDefined();
expect(response.Id).toBeTruthy();
expect(response.ExpenseClaims.length).toBe(1);
expect(response.ExpenseClaims[0].ExpenseClaimID).toBeTruthy();
});
// it('get history', async () => {
// let response = await xero.expenseClaims.history.get({ ExpenseClaimID: await getOrCreateExpenseClaimId(xero) });
// expect(response.HistoryRecords[0]).toBeDefined();
// });
it('get all', async () => {
const response = await xero.expenseClaims.get();
expect(response).toBeDefined();
expect(response.Id).toBeTruthy();
expect(response.ExpenseClaims.length).toBeGreaterThan(0);
expect(response.ExpenseClaims[0].ExpenseClaimID).toBeTruthy();
});
it('update', async () => {
const response = await xero.expenseClaims.update({
ExpenseClaimID: await getOrCreateExpenseClaimId(xero),
Status: 'VOIDED'
});
expect(response).toBeDefined();
expect(response.Id).toBeTruthy();
expect(response.ExpenseClaims.length).toBe(1);
expect(response.ExpenseClaims[0].ExpenseClaimID).toBeTruthy();
expect(response.ExpenseClaims[0].Status).toEqual('VOIDED');
});
afterAll(async () => {
const expenseClaimsToUpdate = idsToArchive.map((id) => ({
ExpenseClaimID: id,
Status: 'VOIDED'
}));
await xero.expenseClaims.update({
ExpenseClaims: expenseClaimsToUpdate
});
});
function collectIdsToArchive(response: ExpenseClaimsResponse) {
idsToArchive = idsToArchive.concat(response.ExpenseClaims.map((expenseClaim) => expenseClaim.ExpenseClaimID));
}
});