Commit 5339f7a7 authored by Farid Neshat's avatar Farid Neshat

Some last minute fixes

parent 81b91378
......@@ -113,7 +113,7 @@ request vacation for 3 days from next week
request conference leave from 12th Jan till 16th Jan because I'm going for the OlinCon!
request sick leave on tomorrow 12pm till 4pm because I have to go to dentist.
I understand human dates, and I know about your 9 to 6 working hours and the fact that you don't have to work.
I understand human dates, and I know about your 9 to 6 working hours and the fact that you don't have to work on weekends :).
I will try to guess the end date and the period, but in case if I was wrong, use all 3 keywords(from, for, till):
request sick leave from tomorrow till saturday for 20 hours because I got the flu.
......
......@@ -5,7 +5,7 @@
// HUBOT_BAMBOOHR_APIKEY, HUBOT_BAMBOOHR_DOMAIN
//
// Commands
// hubot show [<type>] [<status>|all] [mine] [<user>'s] [last] time[-]off[s] [from|on <date>] [[un]till|to <date>]
// hubot show [<type>] [<status>|all] [my] [<user>'s] [last] time[-]off[s] [from|on <date>] [[un]till|to <date>]
//
// Notes:
//
......@@ -25,7 +25,7 @@ const assert = require('assert');
module.exports = function(robot) {
robot.respond(/show *(.+?) *time-?offs?\s*(.*?)\s*$/i, res => {
let [, keywords, args] = res.match;
let { all, type, status, lastOnly, mineOnly, employeeSearch } = parseShowKeywords(keywords);
let { all, type, status, lastOnly, myOnly, employeeSearch } = parseShowKeywords(keywords);
bamboohr.employeesAsync().then(employees => {
let query = ['Searching for'];
......@@ -34,7 +34,7 @@ module.exports = function(robot) {
};
const profile = res.message.user.profile;
const email = profile && profile.email;
if (mineOnly) {
if (myOnly) {
if (!email) {
res.reply("You don't have an email associated with your user.");
return;
......@@ -114,12 +114,15 @@ module.exports = function(robot) {
res.send(query.join(' '));
return bamboohr.timeOffRequestsAsync(options).then(requests => {
if (!requests.length) {
res.reply("Hmm... Sorry I couldn't find any timeoff requests.")
}
if (lastOnly) {
requests = requests.slice(-1);
}
requests.forEach(request => {
let sentence = [];
if (!mineOnly) {
if (!myOnly) {
const employee = employees.find(employee => employee.id === request.employeeId);
let name;
if (employee) {
......@@ -152,14 +155,14 @@ const statuses = ["approved", "denied", "superceded", "pending", "requested", "c
const parseShowKeywords = module.exports.parseShowKeywords = keywords => {
keywords = keywords.split(/\s+/);
let result = {
mineOnly: false,
myOnly: false,
lastOnly: false,
status: 'pending',
all: false
};
keywords.forEach(keyword => {
if (keyword === 'my') {
result.mineOnly = true;
result.myOnly = true;
} else if (keyword === 'last') {
result.lastOnly = true;
} else if (keyword === 'all') {
......
......@@ -78,15 +78,15 @@ describe('Show', function() {
describe('Parsing keywords', function () {
it('nothing', function () {
expect(script.parseShowKeywords('')).to.be.eql({
mineOnly: false,
myOnly: false,
lastOnly: false,
status: 'pending',
all: false,
});
});
it('mine', function () {
it('my', function () {
expect(script.parseShowKeywords('my')).to.be.eql({
mineOnly: true,
myOnly: true,
lastOnly: false,
status: 'pending',
all: false,
......@@ -94,7 +94,7 @@ describe('Show', function() {
});
it('pending', function () {
expect(script.parseShowKeywords('my')).to.be.eql({
mineOnly: true,
myOnly: true,
lastOnly: false,
status: 'pending',
all: false,
......@@ -102,7 +102,7 @@ describe('Show', function() {
});
it('last', function () {
expect(script.parseShowKeywords('last')).to.be.eql({
mineOnly: false,
myOnly: false,
lastOnly: true,
status: 'pending',
all: false,
......@@ -110,7 +110,7 @@ describe('Show', function() {
});
it('other status', function () {
expect(script.parseShowKeywords('my denied')).to.be.eql({
mineOnly: true,
myOnly: true,
lastOnly: false,
status: 'denied',
all: false,
......@@ -118,14 +118,14 @@ describe('Show', function() {
});
it('with type', function () {
expect(script.parseShowKeywords('vacation')).to.nested.include({
mineOnly: false,
myOnly: false,
lastOnly: false,
status: 'pending',
'type.shortName': 'vacation',
all: false,
});
expect(script.parseShowKeywords('sick leave')).to.nested.include({
mineOnly: false,
myOnly: false,
lastOnly: false,
status: 'pending',
'type.shortName': 'sick',
......@@ -134,7 +134,7 @@ describe('Show', function() {
});
it('all', function () {
expect(script.parseShowKeywords('all')).to.be.eql({
mineOnly: false,
myOnly: false,
lastOnly: false,
status: undefined,
all: true,
......@@ -217,7 +217,7 @@ describe('Show', function() {
});
});
});
it('mine', function () {
it('my', function () {
return this.room.user.say('bob', 'hubot show my time-off', {
profile: { email: stubs.email }
}).then(() => {
......
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