forked from XeroAPI/xero-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemployees.integration.tests.ts
77 lines (61 loc) · 2.38 KB
/
employees.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
import { Employee } from '../AccountingAPI-models';
import { EmployeesResponse } from '../AccountingAPI-responses';
import { AccountingAPIClient } from '../AccountingAPIClient';
import { getOrCreateEmployeeId } from './helpers/entityId.helpers';
import { getPrivateConfig, setJestTimeout } from './helpers/integration.helpers';
describe('/employees', () => {
let xero: AccountingAPIClient;
let employeeIdsToArchive: string[] = [];
beforeAll(() => {
setJestTimeout();
const config = getPrivateConfig('1');
xero = new AccountingAPIClient(config);
});
it('create single', async () => {
const response = await xero.employees.create({
FirstName: 'Bryan',
LastName: 'Tee' + Date.now()
});
collectEmployeesToArchive(response);
expect(response.Employees.length).toBe(1);
expect(response.Employees[0].FirstName).toEqual('Bryan');
});
it('get single', async () => {
const response = await xero.employees.get({ EmployeeID: await getOrCreateEmployeeId(xero) });
expect(response).toBeDefined();
expect(response.Id).toBeTruthy();
expect(response.Employees.length).toBe(1);
expect(response.Employees[0].EmployeeID).toBeTruthy();
});
it('get all', async () => {
const response = await xero.employees.get();
expect(response).toBeDefined();
expect(response.Id).toBeTruthy();
expect(response.Employees.length).toBeGreaterThan(0);
expect(response.Employees[0].EmployeeID).toBeTruthy();
});
// skip: looks like archiving an employee doesn't work through the API, this test always fails
it.skip('update', async () => {
const response = await xero.employees.update({
EmployeeID: await getOrCreateEmployeeId(xero),
Status: 'ARCHIVED'
});
expect(response).toBeDefined();
expect(response.Id).toBeTruthy();
expect(response.Employees.length).toBe(1);
expect(response.Employees[0].EmployeeID).toBeTruthy();
expect(response.Employees[0].Status).toEqual('ARCHIVED');
});
afterAll(async () => {
const employeeToUpdate: Employee[] = employeeIdsToArchive.map((employeeId) => ({
EmployeeID: employeeId,
Status: 'ARCHIVED'
}));
await xero.employees.update({
Employees: employeeToUpdate
});
});
function collectEmployeesToArchive(response: EmployeesResponse) {
employeeIdsToArchive = employeeIdsToArchive.concat(response.Employees.map((employee) => employee.EmployeeID));
}
});