forked from XeroAPI/xero-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontactgroups.integration.tests.ts
99 lines (74 loc) · 3.34 KB
/
contactgroups.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { AccountingAPIClient } from '../AccountingAPIClient';
import { getOrCreateContactGroupId, getOrCreateContactId, getOrCreateContactIdInContactGroup } from './helpers/entityId.helpers';
import { getPrivateConfig, setJestTimeout } from './helpers/integration.helpers';
import { isUUID } from './helpers/test-assertions';
describe('/contactgroups', () => {
let xero: AccountingAPIClient;
let _idsToDelete: string[] = [];
beforeAll(async () => {
setJestTimeout();
const config = getPrivateConfig('1');
xero = new AccountingAPIClient(config);
});
it('get single', async () => {
const response = await xero.contactGroups.get({ ContactGroupID: await getOrCreateContactGroupId(xero) });
expect(response).not.toBeNull();
expect(isUUID(response.Id)).toBeTruthy();
expect(response.ContactGroups.length).toBe(1);
});
it('get all', async () => {
const response = await xero.contactGroups.get();
expect(response).not.toBeNull();
expect(isUUID(response.Id)).toBeTruthy();
expect(response.ContactGroups.length).toBeGreaterThan(0);
});
it('create', async () => {
const uniqueName = 'NewContactGroup' + new Date().getTime();
const response = await xero.contactGroups.create({
Name: uniqueName,
Status: 'ACTIVE'
});
_idsToDelete = _idsToDelete.concat(response.ContactGroups[0].ContactGroupID);
expect(response).not.toBeNull();
expect(isUUID(response.ContactGroups[0].ContactGroupID)).toBeTruthy();
expect(response.ContactGroups[0].Name).toBe(uniqueName);
});
it('delete', async () => {
const response = await xero.contactGroups.update({
ContactGroupID: await getOrCreateContactGroupId(xero, false),
Status: 'DELETED'
});
expect(response).not.toBeNull();
expect(response.ContactGroups.length).toBe(1);
expect(response.ContactGroups[0].Status).toBe('DELETED');
});
describe('contacts', async () => {
it('add to group', async () => {
const contactId = await getOrCreateContactId(xero);
const response = await xero.contactGroups.contacts.create({ ContactID: contactId }, { ContactGroupID: await getOrCreateContactGroupId(xero) });
expect(response.Contacts.length).toBe(1);
});
it('delete all from group', async () => {
const contactGroupId = await getOrCreateContactGroupId(xero);
const response = await xero.contactGroups.contacts.delete({ ContactGroupID: contactGroupId });
expect(response).toBeNull();
const getResponse = await xero.contactGroups.get({ ContactGroupID: contactGroupId });
expect(getResponse.ContactGroups[0].Contacts.length).toBe(0);
});
it('delete single from group', async () => {
const contactGroupId = await getOrCreateContactGroupId(xero);
const contactId = await getOrCreateContactIdInContactGroup(xero, contactGroupId);
expect.assertions(2);
const response = await xero.contactGroups.contacts.delete({ ContactGroupID: contactGroupId, ContactID: contactId });
expect(response).toBeNull();
const getResponse = await xero.contactGroups.get({ ContactGroupID: contactGroupId });
expect(getResponse.ContactGroups[0].Contacts.map((contact) => contact.ContactID)).not.toContainEqual(contactId);
});
});
afterAll(async () => {
await Promise.all(_idsToDelete.map((id) => xero.contactGroups.update({
ContactGroupID: id,
Status: 'DELETED'
})));
});
});