Commit 5967cdc7 authored by Farid Neshat's avatar Farid Neshat

Fix not all timeoffs are shown

parent 4a1539aa
{
"name": "hubot-bamboohr-timeoff",
"version": "0.0.0",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -1283,12 +1283,12 @@
"dev": true
},
"node-bamboohr": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/node-bamboohr/-/node-bamboohr-1.0.1.tgz",
"integrity": "sha512-wiAtQVsdYjhdpYRgjasKda47iDYkQycFc43i6/32G4+cPXyRIf/uApQWXCnkqrfsepQu/wh6C9wO8Yntl9numQ==",
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/node-bamboohr/-/node-bamboohr-1.0.2.tgz",
"integrity": "sha512-D51V1Wow3rx8np5hMQFL56Cr7owawCRJPJ5zCjxzQ6LUgJoFZ3NWwchZ7n05WlafgTOqUvutKiWULFj2O1RgDg==",
"requires": {
"request": "2.81.0",
"xml2js": "0.4.18"
"xml2js": "0.4.19"
}
},
"oauth-sign": {
......@@ -1906,18 +1906,18 @@
"dev": true
},
"xml2js": {
"version": "0.4.18",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.18.tgz",
"integrity": "sha512-MMUtkwryoXmYoFUBT32tf7vYPHr98h6VtRLVbsjfmS5hqpp/deRMUNLZNQUHEAY4ChwyBEkisDYhH/EP15X6oA==",
"version": "0.4.19",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
"integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
"requires": {
"sax": "1.2.4",
"xmlbuilder": "9.0.3"
"xmlbuilder": "9.0.4"
}
},
"xmlbuilder": {
"version": "9.0.3",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.3.tgz",
"integrity": "sha1-K5dd2fbHzKyEu10xbZSPcrBv+s8="
"version": "9.0.4",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.4.tgz",
"integrity": "sha1-UZy0ymhtAFqEINNJbz8MruzKWA8="
}
}
}
{
"name": "hubot-bamboohr-timeoff",
"description": "A hubot scripts that adds the ablity to make timeoff requests and their approval",
"version": "0.0.0",
"version": "0.0.1",
"author": "Farid Neshat <FaridN_SOAD@Yahoo.com>",
"license": "MIT",
"keywords": [
......@@ -23,7 +23,7 @@
"hubot-conversation": "^1.1.1",
"moment": "^2.18.1",
"moment-business-time": "^0.7.0",
"node-bamboohr": "^1.0.1",
"node-bamboohr": "^1.0.2",
"sugar": "^2.0.4",
"timestring": "^5.0.0"
},
......
// Description
// A hubot scripts that adds the ability to make timeoff requests and manage them for BambooHR
// A hubot scripts that adds the ability to show timeoff requests
//
// Configuration:
// HUBOT_BAMBOOHR_APIKEY, HUBOT_BAMBOOHR_DOMAIN
//
// Commands
// hubot timeoff help
// hubot request [<type>] timeoff|leave|vacation [from|on <date>] [for <period>] [[un]till|to <date>] [because <reason>]
// hubot show [<type>] [<status>|all] [mine] [<user>'s] [last] time[-]off[s] [from|on <date>] [[un]till|to <date>]
//
// Notes:
//
......@@ -30,9 +29,7 @@ module.exports = function(robot) {
bamboohr.employeesAsync().then(employees => {
let query = ['Searching for'];
const options = {
action: 'approve',
};
const options = {};
const profile = res.message.user.profile;
const email = profile && profile.email;
if (mineOnly) {
......
'use strict';
require('coffee-script/register');
const Helper = require('hubot-test-helper');
const sinon = require('sinon');
const chai = require('chai');
chai.use(require('sinon-chai'));
const { expect } = chai;
// Must be required before the script to stub everything properly
const stubs = require('./stubs');
const sctiptPath = '../src/scripts/request.js';
const helper = new Helper(sctiptPath);
describe('Approve', function() {
beforeEach(function() {
this.room = helper.createRoom({
name: 'bob',
});
});
afterEach(function() {
this.room.destroy();
});
it('from for', function() {
return this.room.user.say('bob', 'hubot approve all timeoff').then(() => {
expect(this.room.messages[1][1]).to.be.equal('@bob So you want to approve the following timeoffs?\n\nFarid\'s vacation from Tue Jul 25' +
' 2017 to Wed Jul 26 for 16 working hours');
});
})
});
'use strict';
const { Array } = require('sugar');
require('coffee-script/register');
const Helper = require('hubot-test-helper');
const sinon = require('sinon');
......@@ -19,9 +21,44 @@ const helper = new Helper(sctiptPath);
describe('Show', function() {
before(function () {
this.clock = sinon.useFakeTimers(Date.parse('1 July 2017'));
Bamboohr.prototype.timeOffRequests.callsFake(function (options, cb) {
console.log('called')
if (options.type) {
options = { ...options, type: 'Sick Leave' };
}
cb(null, Array.filter([{
start: '2011-10-02',
end: '2011-10-01',
created: '2011-10-02',
type: 'Vacation',
amount: 5,
amountUnit: 'days',
status: 'requested',
employeeId: stubs.employeeId,
}, {
start: '2011-10-03',
end: '2011-10-01',
created: '2011-10-02',
type: 'Sick Leave',
amount: 5,
amountUnit: 'days',
status: 'requested',
employeeId: stubs.employeeId,
}, {
start: '2011-10-01',
end: '2011-10-01',
created: '2011-10-01',
type: 'Vacation',
amount: 5,
amountUnit: 'days',
status: 'approved',
employeeId: stubs.employeeId,
}], options));
});
});
after(function () {
this.clock.restore();
Bamboohr.prototype.timeOffRequests.resetBehavior();
});
beforeEach(function() {
this.room = helper.createRoom({
......@@ -103,7 +140,6 @@ describe('Show', function() {
it('simple', function () {
return this.room.user.say('bob', 'hubot show time-offs').then(() => {
expect(Bamboohr.prototype.timeOffRequests).to.have.been.calledWith({
action: 'approve',
status: 'requested',
});
expect(this.room.messages).to.have.lengthOf(4).and.nested.property('2.1').to.be.equal(
......@@ -115,7 +151,6 @@ describe('Show', function() {
it('all', function () {
return this.room.user.say('bob', 'hubot show all time-offs').then(() => {
expect(Bamboohr.prototype.timeOffRequests).to.have.been.calledWith({
action: 'approve',
});
expect(this.room.messages[1][1]).to.be.equal('@bob Searching for time-offs');
expect(this.room.messages[2][1]).to.be.equal(
......@@ -127,7 +162,6 @@ describe('Show', function() {
it('last', function () {
return this.room.user.say('bob', 'hubot show last time-off').then(() => {
expect(Bamboohr.prototype.timeOffRequests).to.have.been.calledWith({
action: 'approve',
status: 'requested',
});
expect(this.room.messages).to.have.lengthOf(3).and.nested.property('2.1').to.be.equal(
......@@ -137,7 +171,6 @@ describe('Show', function() {
it('with type', function () {
return this.room.user.say('bob', 'hubot show sick leave time-off').then(() => {
expect(Bamboohr.prototype.timeOffRequests).to.have.been.calledWith({
action: 'approve',
status: 'requested',
type: 2
});
......@@ -151,7 +184,6 @@ describe('Show', function() {
return this.room.user.say('bob', 'hubot show leave time-off on today').then(() => {
expect(this.room.messages[1][1]).to.be.equal('@bob Searching for pending time-offs on Sat Jul 1');
expect(Bamboohr.prototype.timeOffRequests).to.have.been.calledWith({
action: 'approve',
status: 'requested',
start: new Date('2017/07/01'),
end: new Date('2017/07/01'),
......@@ -162,7 +194,6 @@ describe('Show', function() {
return this.room.user.say('bob', 'hubot show leave time-off from tomorrow').then(() => {
expect(this.room.messages[1][1]).to.be.equal('@bob Searching for pending time-offs from Sat Jul 1');
expect(Bamboohr.prototype.timeOffRequests).to.have.been.calledWith({
action: 'approve',
status: 'requested',
start: new Date('2017/07/02'),
});
......@@ -171,7 +202,6 @@ describe('Show', function() {
it('from', function () {
return this.room.user.say('bob', 'hubot show leave time-off to tomorrow').then(() => {
expect(Bamboohr.prototype.timeOffRequests).to.have.been.calledWith({
action: 'approve',
status: 'requested',
end: new Date('2017/07/02'),
});
......@@ -182,7 +212,6 @@ describe('Show', function() {
profile: { email: stubs.email }
}).then(() => {
expect(Bamboohr.prototype.timeOffRequests).to.have.been.calledWith({
action: 'approve',
status: 'requested',
employeeId: stubs.employeeId,
});
......@@ -194,7 +223,6 @@ describe('Show', function() {
return this.room.user.say('bob', `hubot show ${stubs.name}'s time-off`).then(() => {
expect(this.room.messages[1][1]).to.be.equal(`@bob Searching for pending ${stubs.email}'s time-offs`);
expect(Bamboohr.prototype.timeOffRequests).to.have.been.calledWith({
action: 'approve',
status: 'requested',
employeeId: stubs.employeeId,
});
......
......@@ -33,42 +33,7 @@ const stubs = [
workEmail: exports.email,
})]);
}),
sinon.stub(Bamboohr.prototype, 'timeOffRequests').callsFake(function (options, cb) {
if (options.type) {
options = { ...options, type: 'Sick Leave' };
}
cb(null, Array.filter([{
start: '2011-10-02',
end: '2011-10-01',
created: '2011-10-02',
type: 'Vacation',
amount: 5,
amountUnit: 'days',
status: 'requested',
action: 'approve',
employeeId: exports.employeeId,
}, {
start: '2011-10-03',
end: '2011-10-01',
created: '2011-10-02',
type: 'Sick Leave',
amount: 5,
amountUnit: 'days',
status: 'requested',
action: 'approve',
employeeId: exports.employeeId,
}, {
start: '2011-10-01',
end: '2011-10-01',
created: '2011-10-01',
type: 'Vacation',
amount: 5,
amountUnit: 'days',
status: 'approved',
action: 'approve',
employeeId: exports.employeeId,
}], options));
})
sinon.stub(Bamboohr.prototype, 'timeOffRequests'),
];
beforeEach(function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment