forked from XeroAPI/xero-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contacts.integration.tests.ts
60 lines (46 loc) · 1.67 KB
/
contacts.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
import { ContactsResponse } from '../AccountingAPI-responses';
import { AccountingAPIClient } from '../AccountingAPIClient';
import { getPrivateConfig, setJestTimeout } from './helpers/integration.helpers';
describe('/contacts', () => {
let xero: AccountingAPIClient;
let contactIdsToArchive: string[] = [];
beforeAll(() => {
setJestTimeout();
const config = getPrivateConfig('1');
xero = new AccountingAPIClient(config);
});
it('create contacts', async () => {
const response = await xero.contacts.create({
Contacts: [{
Name: 'Bryan Tee' + new Date()
}, {
Name: 'Phil Tee' + new Date()
}]
});
collectContactsToArchive(response);
expect(response.Contacts.length).toBe(2);
expect(response.Contacts[0].Name).toContain('Bryan');
expect(response.Contacts[1].Name).toContain('Phil');
});
it('gets a contact by ID', async () => {
const response = await xero.contacts.get({ ContactID: contactIdsToArchive[0] });
expect(response.Contacts[0].ContactID).toBeDefined();
});
// it('can get history', async () => {
// const response = await xero.contacts.history.get({ ContactID: contactIdsToArchive[0] });
// expect(response.HistoryRecords[0]).toBeDefined();
// });
afterAll(async () => {
// And this is how you update
const contactsToUpdate = contactIdsToArchive.map((contactId) => ({
ContactID: contactId,
Status: 'ARCHIVED'
}));
await xero.contacts.update({
Contacts: contactsToUpdate
});
});
function collectContactsToArchive(response: ContactsResponse) {
contactIdsToArchive = contactIdsToArchive.concat(response.Contacts.map((contact) => contact.ContactID));
}
});