-
Notifications
You must be signed in to change notification settings - Fork 3
/
bot.test.js
72 lines (63 loc) · 1.85 KB
/
bot.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
const { bot } = require("../bot");
let outgoingRequests = [];
function generateMessage(message) {
return {
update_id: 10000,
message: {
date: 1441645532,
chat: {
last_name: "Test Lastname",
id: 1111111,
first_name: "Test",
username: "Test",
},
message_id: 1365,
from: {
last_name: "Test Lastname",
id: 1111111,
first_name: "Test",
username: "Test",
},
text: message,
},
};
}
beforeAll(async () => {
bot.api.config.use((prev, method, payload, signal) => {
outgoingRequests.push({ method, payload, signal });
return { ok: true, result: true };
});
bot.botInfo = {
id: 42,
first_name: "Test Bot",
is_bot: true,
username: "bot",
can_join_groups: true,
can_read_all_group_messages: true,
supports_inline_queries: false,
};
await bot.init();
}, 5000);
beforeEach(() => {
outgoingRequests = [];
});
test("reset; three time plus, two time minus", async () => {
await bot.handleUpdate(generateMessage("reset"));
await bot.handleUpdate(generateMessage("+"));
await bot.handleUpdate(generateMessage("+"));
await bot.handleUpdate(generateMessage("+"));
await bot.handleUpdate(generateMessage("-"));
await bot.handleUpdate(generateMessage("-"));
expect(outgoingRequests.length).toBe(6);
expect(outgoingRequests.pop().payload.text).toBe(1);
}, 5000);
test("reset; two times plus, three time minus", async () => {
await bot.handleUpdate(generateMessage("reset"));
await bot.handleUpdate(generateMessage("+"));
await bot.handleUpdate(generateMessage("+"));
await bot.handleUpdate(generateMessage("-"));
await bot.handleUpdate(generateMessage("-"));
await bot.handleUpdate(generateMessage("-"));
expect(outgoingRequests.length).toBe(6);
expect(outgoingRequests.pop().payload.text).toBe(-1);
}, 5000);