import { BambooHRClient } from '../src/client'; import { expect } from 'chai'; import 'mocha'; import { mockRequests, mockStatusForRequest } from './mocks'; const client = new BambooHRClient("id", "secret"); describe('BambooHRClient', () => { beforeEach(() => { mockRequests(); }); describe('getDirectory()', () => { it('should get the directory basic profile info', () => { return client.getDirectory() .then((directory) => { expect(directory).to.be.a('Array'); expect(directory.length).to.be.equal(4); expect(directory[0].id).to.equal(10); }); }); it('should get the project tracking for each employee', () => { return client.getDirectory() .then((directory) => { expect(directory[0].projects).to.be.a('Array'); expect(directory[0].projects.length).to.be.equal(1); expect(directory[1].projects).to.be.a('Array'); expect(directory[1].projects.length).to.be.equal(2); expect(directory[2].projects).to.be.a('Array'); expect(directory[2].projects.length).to.be.equal(3); expect(directory[3].projects).to.be.a('Array'); expect(directory[3].projects.length).to.be.equal(0); }); }); it('should get the employeeNumber, payRate, hireDate and location data', () => { expect.fail(0, 1, 'Not implemented yet'); }); }); describe('getEmployee()', () => { it('should find an employee by id', () => { return client.getEmployee(44) .then((response) => { expect(response.id).to.equal(44); expect(response.displayName).to.equal('Karen Morgan'); expect(response.employeeNumber).to.equal(46); expect(response.jobTitle).to.equal('Web Designer'); expect(response.payRate).to.equal('2500.00 USD'); expect(response.payRateValue).to.equal(2500); expect(response.location).to.equal('CR - Real Cariari'); }); }); it('should throw an error for non existing employees', () => { // mock http response mockStatusForRequest('/api/gateway.php/firstfactory/v1/employees/8888', 404, true); return client.getEmployee(8888) .then((response) => { expect.fail(0, 1, 'Exception not thrown'); }) .catch((error) => { expect(error.response.status).to.be.equal(404); }); }); }); describe('getProjectTracking()', () => { it('should fetch the project list for the whole company', () => { return client.getProjectTracking() .then((response) => { expect(response).to.be.a('Array'); expect(response.length).to.be.equal(6); expect(response[0]).to.include({ employeeId: 10, customProject: 'First Factory', customBillableRate: 45.0 }); expect(response[1]).to.include({ employeeId: 22, customProject: 'Project Alpha', customBillableRate: 60.0 }); expect(response[2]).to.include({ employeeId: 22, customProject: 'Project Beta', customBillableRate: 60.0 }); expect(response[3]).to.include({ employeeId: 44, customProject: 'Project Alpha', customBillableRate: 60.0 }); expect(response[4]).to.include({ employeeId: 44, customProject: 'Project Alpha', customBillableRate: 65.0 }); expect(response[5]).to.include({ employeeId: 44, customProject: 'Open World', customBillableRate: 65.0 }); }); }); it('should fetch the project list of an employee', () => { return client.getProjectTracking(44) .then((response) => { expect(response).to.be.a('Array'); expect(response.length).to.be.equal(3); expect(response[0]).to.include({ employeeId: 44, customProject: 'Project Alpha', customBillableRate: 60.0 }); expect(response[1]).to.include({ employeeId: 44, customProject: 'Project Alpha', customBillableRate: 65.0 }); expect(response[2]).to.include({ employeeId: 44, customProject: 'Open World', customBillableRate: 65.0 }); }); }); }); });