/
index.test.js
168 lines (158 loc) · 6.25 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const bot = require("./index.js");
function newMessage(text) {
return {
message: {
chat: {
id: 1,
},
text,
}
};
}
function newInlineQuery(query) {
return {
inline_query: {
id: 1,
query,
}
};
}
describe("when messaged directly", () => {
test("with full pokemon name", () => {
const json = jest.fn();
bot.handler({body: newMessage("turtwig")}, {json});
expect(json.mock.calls[0][0]).toEqual({
"chat_id": 1,
"method": "sendMessage",
"parse_mode": "Markdown",
"text": `*Turtwig (#387)*
Type: Grass
Weak against: Bug (2x), Fire (2x), Flying (2x), Ice (2x), Poison (2x)
Resistant to: Electric (0.5x), Grass (0.5x), Ground (0.5x), Water (0.5x)
Abilities: Overgrow
Height: 1' 4"
Weight: 22.5 lbs
[Image](https://assets.pokemon.com/assets/cms2/img/pokedex/full/387.png)`
});
});
test("with partial pokemon name", () => {
const json = jest.fn();
bot.handler({body: newMessage("turt")}, {json});
expect(json.mock.calls[0][0]).toEqual({
"chat_id": 1,
"method": "sendMessage",
"parse_mode": "Markdown",
"text": `*Turtwig (#387)*
Type: Grass
Weak against: Bug (2x), Fire (2x), Flying (2x), Ice (2x), Poison (2x)
Resistant to: Electric (0.5x), Grass (0.5x), Ground (0.5x), Water (0.5x)
Abilities: Overgrow
Height: 1' 4"
Weight: 22.5 lbs
[Image](https://assets.pokemon.com/assets/cms2/img/pokedex/full/387.png)`
});
});
test("with nonexistent pokemon name", () => {
const json = jest.fn();
bot.handler({body: newMessage("digimon")}, {json});
expect(json.mock.calls[0][0]).toEqual({
"chat_id": 1,
"method": "sendMessage",
"text": "Couldn't find a matching Pokémon!"
});
});
test("weakness and immunity", () => {
const json = jest.fn();
bot.handler({body: newMessage("whiscash")}, {json});
expect(json.mock.calls[0][0]).toEqual({
"chat_id": 1,
"method": "sendMessage",
"parse_mode": "Markdown",
"text": `*Whiscash (#340)*
Type: Water/Ground
Weak against: Grass (4x)
Resistant to: Fire (0.5x), Poison (0.5x), Rock (0.5x), Steel (0.5x)
Immune to: Electric (0x)
Abilities: Anticipation, Oblivious
Height: 2' 11"
Weight: 52 lbs
[Image](https://assets.pokemon.com/assets/cms2/img/pokedex/full/340.png)`
});
});
test("weakness and immunity 2", () => {
const json = jest.fn();
bot.handler({body: newMessage("froslass")}, {json});
expect(json.mock.calls[0][0]).toEqual({
"chat_id": 1,
"method": "sendMessage",
"parse_mode": "Markdown",
"text": `*Froslass (#478)*
Type: Ice/Ghost
Weak against: Dark (2x), Fire (2x), Ghost (2x), Rock (2x), Steel (2x)
Resistant to: Bug (0.5x), Ice (0.5x), Poison (0.5x)
Immune to: Fighting (0x), Normal (0x)
Abilities: Snow Cloak
Height: 4' 3"
Weight: 58.6 lbs
[Image](https://assets.pokemon.com/assets/cms2/img/pokedex/full/478.png)`
});
});
});
describe("when sent an inline query", function () {
test("with full pokemon name", () => {
const json = jest.fn();
bot.handler({body: newInlineQuery("turtwig")}, {json});
const reply = json.mock.calls[0][0];
expect(reply.inline_query_id).toEqual(1);
expect(reply.method).toEqual("answerInlineQuery");
expect(JSON.parse(reply.results)).toEqual([
{
"description": "Grass",
"id": 387,
"input_message_content": {
"message_text": "*Turtwig (#387)*\nType: Grass\nWeak against: Bug (2x), Fire (2x), Flying (2x), Ice (2x), Poison (2x)\nResistant to: Electric (0.5x), Grass (0.5x), Ground (0.5x), Water (0.5x)\nAbilities: Overgrow\nHeight: 1' 4\"\nWeight: 22.5 lbs\n[Image](https://assets.pokemon.com/assets/cms2/img/pokedex/full/387.png)",
"parse_mode": "Markdown"
},
"thumb_url": "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/387.png",
"title": "Turtwig (#387)",
"type": "article"
}
]);
});
test("with partial pokemon name", () => {
const json = jest.fn();
bot.handler({body: newInlineQuery("turt")}, {json});
const reply = json.mock.calls[0][0];
expect(reply.inline_query_id).toEqual(1);
expect(reply.method).toEqual("answerInlineQuery");
expect(JSON.parse(reply.results)).toEqual([
{
"description": "Grass",
"id": 387,
"input_message_content": {
"message_text": "*Turtwig (#387)*\nType: Grass\nWeak against: Bug (2x), Fire (2x), Flying (2x), Ice (2x), Poison (2x)\nResistant to: Electric (0.5x), Grass (0.5x), Ground (0.5x), Water (0.5x)\nAbilities: Overgrow\nHeight: 1' 4\"\nWeight: 22.5 lbs\n[Image](https://assets.pokemon.com/assets/cms2/img/pokedex/full/387.png)",
"parse_mode": "Markdown"
},
"thumb_url": "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/387.png",
"title": "Turtwig (#387)",
"type": "article"
},
{
"description": "Fire/Dragon",
"id": 776,
"input_message_content": {
"message_text": "*Turtonator (#776)*\nType: Fire/Dragon\nWeak against: Dragon (2x), Ground (2x), Rock (2x)\nResistant to: Bug (0.5x), Electric (0.5x), Steel (0.5x), Fire (0.25x), Grass (0.25x)\nAbilities: Shell Armor\nHeight: 6' 7\"\nWeight: 467.4 lbs\n[Image](https://assets.pokemon.com/assets/cms2/img/pokedex/full/776.png)",
"parse_mode": "Markdown"
},
"thumb_url": "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/776.png",
"title": "Turtonator (#776)",
"type": "article"
}
]);
});
test("with nonexistent pokemon name", () => {
const sendStatus = jest.fn();
bot.handler({body: newInlineQuery("digimon")}, {sendStatus});
expect(sendStatus.mock.calls[0][0]).toEqual(200);
});
});