Skip to content

Commit

Permalink
Merge pull request #537 from 18F/514-holiday-threads
Browse files Browse the repository at this point in the history
If holiday is requested in a thread, respond in the thread
  • Loading branch information
mgwalker authored Jul 3, 2024
2 parents acbb388 + 9d5e142 commit 32c4d18
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
12 changes: 8 additions & 4 deletions src/scripts/federal-holidays.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ module.exports = (app) => {
},
}));

app.message(directMention(), /next (federal )?holiday/i, ({ say }) => {
say(getHolidayText());
incrementStats("next federal holiday request");
});
app.message(
directMention(),
/next (federal )?holiday/i,
({ event: { thread_ts: thread }, say }) => {
say({ text: getHolidayText(), thread_ts: thread });
incrementStats("next federal holiday request");
},
);
};
36 changes: 20 additions & 16 deletions src/scripts/federal-holidays.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ describe("federal holidays bot", () => {
name: "Test Holiday day",
});

handler({ say });
handler({ event: {}, say });

expect(say.mock.calls.length).toBe(1);
expect(say).toHaveBeenCalledWith(
"The next federal holiday is Test Holiday day in 1 days on Friday, January 2nd",
);
expect(say).toHaveBeenCalledWith({
text: "The next federal holiday is Test Holiday day in 1 days on Friday, January 2nd",
thread_ts: undefined,
});
});

it("uses an alternate name, if provided", () => {
Expand All @@ -102,12 +103,13 @@ describe("federal holidays bot", () => {
alsoObservedAs: "Other holiday day day day",
});

handler({ say });
handler({ event: { thread_ts: "thread" }, say });

expect(say.mock.calls.length).toBe(1);
expect(say).toHaveBeenCalledWith(
"The next federal holiday is Other holiday day day day in 1 days on Friday, January 2nd",
);
expect(say).toHaveBeenCalledWith({
text: "The next federal holiday is Other holiday day day day in 1 days on Friday, January 2nd",
thread_ts: "thread",
});
});
});

Expand All @@ -122,12 +124,13 @@ describe("federal holidays bot", () => {
name: "Christmas Day",
});

handler({ say });
handler({ event: {}, say });

expect(say.mock.calls.length).toBe(1);
expect(say).toHaveBeenCalledWith(
"The next federal holiday is Christmas Day :christmas_tree: in 1 days on Friday, January 2nd",
);
expect(say).toHaveBeenCalledWith({
text: "The next federal holiday is Christmas Day :christmas_tree: in 1 days on Friday, January 2nd",
thread_ts: undefined,
});
});

it("does not include the emoji if the holiday does not have one", () => {
Expand All @@ -141,12 +144,13 @@ describe("federal holidays bot", () => {
alsoObservedAs: "Indigenous Peoples' Day",
});

handler({ say });
handler({ event: {}, say });

expect(say.mock.calls.length).toBe(1);
expect(say).toHaveBeenCalledWith(
"The next federal holiday is Indigenous Peoples' Day in 1 days on Friday, January 2nd",
);
expect(say).toHaveBeenCalledWith({
text: "The next federal holiday is Indigenous Peoples' Day in 1 days on Friday, January 2nd",
thread_ts: undefined,
});
});
});
});

0 comments on commit 32c4d18

Please sign in to comment.