diff --git a/src/notify.coffee b/src/notify.coffee index e9938c0..2c4ee2d 100644 --- a/src/notify.coffee +++ b/src/notify.coffee @@ -74,18 +74,18 @@ formatMessage = (messages, option = 'plain') -> when 'plain' outputMessage = "_Following overlaps found:_\n" for message in messages - outputMessage += """#{message.user}: #{message.schedules[0]} and #{message.schedules[1]} on #{message.date.toUTCString()}\n""" + outputMessage += """#{message.user}: #{message.schedules[0]} and #{message.schedules[1]} (the first starting on #{message.date.toUTCString()}, the second on #{message.crossDate.toUTCString()})\n""" when 'markdown' outputMessage = "Following overlaps found:\n" for message in messages - outputMessage += """*#{message.user}:* `#{message.schedules[0]}` and `#{message.schedules[1]}` on #{message.date.toUTCString()}\n""" + outputMessage += """*#{message.user}:* `#{message.schedules[0]}` and `#{message.schedules[1]}` (the first starting on #{message.date.toUTCString()}, the second on #{message.crossDate.toUTCString()})\n""" when 'json' outputMessage = messages.reduce((acc, curr)-> acc[curr.userId] ?= {} acc[curr.userId].userId ?= curr.userId acc[curr.userId].user ?= curr.user acc[curr.userId].messages ?= [] - acc[curr.userId].messages.push("#{curr.schedules[0]} and #{curr.schedules[1]} #{curr.date.toUTCString()}") + acc[curr.userId].messages.push("#{curr.schedules[0]} and #{curr.schedules[1]} (the first starting on #{curr.date.toUTCString()}, the second on #{curr.crossDate.toUTCString()})") return acc , {}) diff --git a/src/pagerduty.coffee b/src/pagerduty.coffee index 8374612..97300e2 100644 --- a/src/pagerduty.coffee +++ b/src/pagerduty.coffee @@ -124,7 +124,7 @@ processSchedules = (allSchedules, days = [], cb) -> scheduleId = nconf.get("schedulesNames:#{schedule.id}") crossScheduleId = nconf.get("schedulesNames:#{crossSchedule.id}") - message = {user: myUserName, userId: myUserId, schedules: [scheduleId, crossScheduleId], date: startDate} + message = {user: myUserName, userId: myUserId, schedules: [scheduleId, crossScheduleId], date: startDate, crossDate: new Date(crossCheckEntry.start)} if myStart <= crossCheckEntry.start < myEnd and crossCheckEntry.user.id == myUserId diff --git a/test/fixtures/incident.json b/test/fixtures/incident.json index 82bd6c0..9189252 100644 --- a/test/fixtures/incident.json +++ b/test/fixtures/incident.json @@ -8,7 +8,7 @@ }, "body": { "type": "incident_body", - "details": "Primary and Secondary Sun, 19 Aug 2012 16:00:00 GMT" + "details": "Primary and Secondary (the first starting on Sun, 19 Aug 2012 16:00:00 GMT, the second on Sun, 19 Aug 2012 16:00:00 GMT)" }, "assignments": [ { diff --git a/test/fixtures/incident2.json b/test/fixtures/incident2.json index 7614f26..87616e2 100644 --- a/test/fixtures/incident2.json +++ b/test/fixtures/incident2.json @@ -8,7 +8,7 @@ }, "body": { "type": "incident_body", - "details": "Primary and Secondary Sun, 19 Aug 2012 04:00:00 GMT" + "details": "Primary and Secondary (the first starting on Sun, 19 Aug 2012 04:00:00 GMT, the second on Sun, 19 Aug 2012 04:00:00 GMT)" }, "assignments": [ { diff --git a/test/notify-test.coffee b/test/notify-test.coffee index 42ef7ed..abf4df4 100644 --- a/test/notify-test.coffee +++ b/test/notify-test.coffee @@ -16,14 +16,16 @@ describe 'Test send message using notify.send for both', -> actual = null before (done) -> + overlapDate = new Date() message = user: 'Test user' userId: '1234' schedules: ['TEST1', 'TEST2'] - date: new Date() + date: overlapDate + crossDate: overlapDate expectBody = - text:"Following overlaps found:\n*Test user:* `TEST1` and `TEST2` on #{message.date.toUTCString()}\n" + text:"Following overlaps found:\n*Test user:* `TEST1` and `TEST2` (the first starting on #{overlapDate.toUTCString()}, the second on #{overlapDate.toUTCString()})\n" channel:"#channel-name" config.setupConfig configPath, (err) -> @@ -44,7 +46,8 @@ describe 'Test send message using notify.send for both', -> user: 'Test user' userId: '1234' schedules: ['TEST1', 'TEST2'] - date: new Date() + date: overlapDate + crossDate: overlapDate notify.send options, [ message ], (err, result) -> if err then return done err