-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a465cd
commit f1d4299
Showing
4 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { parseNotifyCommand } from "../../../src/listeners/commands/notifyCommand"; | ||
import { NotifyParameters } from "../../../src/listeners/commands/notifyCommand"; | ||
import SlackChannel from "../../../src/classes/SlackChannel"; | ||
|
||
describe("parseNotifyCommand", () => { | ||
it("parses the /notify command", () => { | ||
const commandArgs = "https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000"; | ||
const expected: NotifyParameters = { | ||
messageUrl: "https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000", | ||
pingChannels: false, | ||
channels: "default", | ||
}; | ||
|
||
expect(parseNotifyCommand(commandArgs)).toEqual(expected); | ||
}); | ||
|
||
it("parses the /notify command when link is not plaintext", () => { | ||
const commandArgs = "<https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000>"; | ||
const expected: NotifyParameters = { | ||
messageUrl: "https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000", | ||
pingChannels: false, | ||
channels: "default", | ||
}; | ||
|
||
expect(parseNotifyCommand(commandArgs)).toEqual(expected); | ||
}); | ||
|
||
it("parses the /notify command with pinging channels", () => { | ||
const commandArgs = | ||
"https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000 ping <#C12345678|channel-name> <#C12345679|channel-name2>"; | ||
const expected: NotifyParameters = { | ||
messageUrl: "https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000", | ||
pingChannels: true, | ||
channels: [new SlackChannel("channel-name", "C12345678"), new SlackChannel("channel-name2", "C12345679")], | ||
}; | ||
|
||
expect(parseNotifyCommand(commandArgs)).toEqual(expected); | ||
}); | ||
|
||
it("parses the /notify command with the default channels", () => { | ||
const commandArgs = "https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000"; | ||
const expected: NotifyParameters = { | ||
messageUrl: "https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000", | ||
pingChannels: false, | ||
channels: "default", | ||
}; | ||
|
||
expect(parseNotifyCommand(commandArgs)).toEqual(expected); | ||
}); | ||
|
||
it("parses the /notify command with pinging default channels", () => { | ||
const commandArgs = "https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000 ping"; | ||
const expected: NotifyParameters = { | ||
messageUrl: "https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000", | ||
pingChannels: true, | ||
channels: "default", | ||
}; | ||
|
||
expect(parseNotifyCommand(commandArgs)).toEqual(expected); | ||
}); | ||
|
||
it("throws an error when the command is empty", () => { | ||
const commandArgs = ""; | ||
expect(() => parseNotifyCommand(commandArgs)).toThrow( | ||
"Please provide a message to send. Usage: `/notify <messageURL>`", | ||
); | ||
}); | ||
|
||
it("throws an error when the URL is invalid", () => { | ||
const commandArgs = "https://google.com"; | ||
expect(() => parseNotifyCommand(commandArgs)).toThrow( | ||
"Please provide a valid message URL from this Slack workspace as the first argument.", | ||
); | ||
}); | ||
|
||
it("throws an error when the channels are invalid", () => { | ||
const commandArgs = "https://waterloorocketrydev.slack.com/archives/C015FXXXXXX/p1707843500000000 #C12345678"; | ||
expect(() => parseNotifyCommand(commandArgs)).toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { parseEscapedSlashCommandChannel } from "../../../src/utils/channels"; | ||
|
||
describe("parseEscapedSlashCommandChannel", () => { | ||
it("parses the escaped channel text from a Slack command and returns the Slack channel", () => { | ||
const text = "<#C12345678|channel-name>"; | ||
const expected = { | ||
name: "channel-name", | ||
id: "C12345678", | ||
}; | ||
|
||
expect(parseEscapedSlashCommandChannel(text)).toEqual(expected); | ||
}); | ||
|
||
it("Throws an error when the text is not in the correct format", () => { | ||
const text = "channel-name"; | ||
expect(() => parseEscapedSlashCommandChannel(text)).toThrow(`could not parse escaped channel text: ${text}`); | ||
}); | ||
}); |