Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If holiday is requested in a thread, respond in the thread #537

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
});
});
});
});
Loading