-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
95 lines (84 loc) · 2.43 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const assert = require("assert");
const { BotMock, SlackApiMock } = require("botkit-mock");
const {
SlackAdapter,
SlackMessageTypeMiddleware,
SlackEventMiddleware
} = require("botbuilder-adapter-slack");
const setupBotActions = require("./bot.js");
beforeAll(() => {
const adapter = new SlackAdapter({
clientSigningSecret: "secret",
botToken: "token",
debug: false
});
adapter.use(new SlackEventMiddleware());
adapter.use(new SlackMessageTypeMiddleware());
this.controller = new BotMock({
adapter,
disable_webserver: true
});
SlackApiMock.bindMockApi(this.controller);
setupBotActions(this.controller);
});
describe("Bot Template Tests", () => {
it("Should send the user a help message via direct messaging once the user types help", async () => {
const message = await this.controller.usersInput([
{
user: "someUserId",
channel: "someChannel",
messages: [
{
text: "help",
isAssertion: true
}
]
}
]);
return assert.strictEqual(
message.text,
"This is a help message that I have sent to you via Direct Messaging"
);
});
it("Should send the user a help message in the channel they are currently in, in response to the helpme slashcommand", async () => {
const message = await this.controller.usersInput([
{
type: "slash_command",
user: "someUserId",
channel: "someChannel",
messages: [
{
command: "/helpme",
text: "",
isAssertion: true
}
]
}
]);
return assert.strictEqual(
message.text,
"This is a help message that I have sent to you via a message in a channel"
);
});
//Really this will never happen, the only way it will happen is if the command is written in the slack API website but not implemented in code
it("Should tell the user they have inputted a unknown command in response to the user entering a random command", async () => {
const message = await this.controller.usersInput([
{
type: "slash_command",
user: "someUserId",
channel: "someChannel",
messages: [
{
command: "/iamnotvalid",
text: "",
isAssertion: true
}
]
}
]);
return assert.strictEqual(
message.text,
"Sorry, I did not recognize that command"
);
});
});