forked from XeroAPI/xero-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payments.integration.tests.ts
51 lines (40 loc) · 1.61 KB
/
payments.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
import { AccountingAPIClient } from '../AccountingAPIClient';
import { getOrCreateInvoiceId, getOrCreatePaymentId } from './helpers/entityId.helpers';
import { getPrivateConfig, setJestTimeout } from './helpers/integration.helpers';
describe('/payments', () => {
let xero: AccountingAPIClient;
let _idsToDelete: string[] = [];
beforeAll(async () => {
setJestTimeout();
const config = getPrivateConfig();
xero = new AccountingAPIClient(config);
});
it('can get all', async () => {
const response = await xero.payments.get();
expect(response.Payments).toBeDefined();
});
it('can get single', async () => {
const paymentId = await getOrCreatePaymentId(xero);
const response = await xero.payments.get({ PaymentID: paymentId });
expect(response.Payments.length).toBe(1);
expect(response.Payments[0].Amount).toBeDefined();
});
// it('get history', async () => {
// const paymentId = await getOrCreatePaymentId(xero);
// const response = await xero.payments.history.get({ PaymentID: paymentId });
// expect(response.HistoryRecords[0]).toBeDefined();
// });
it('create', async () => {
const response = await xero.payments.create({
Invoice: { InvoiceID: await getOrCreateInvoiceId(xero) },
Account: { Code: '200' },
Amount: 0.75
});
expect(response.Payments.length).toBe(1);
expect(response.Payments[0].Amount).toEqual(0.75);
_idsToDelete = _idsToDelete.concat(response.Payments[0].PaymentID);
});
afterAll(async () => {
await Promise.all(_idsToDelete.map((id) => xero.payments.update({ Status: 'DELETED' }, { PaymentID: id })));
});
});