-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathslack.test.tsx
More file actions
77 lines (70 loc) · 1.75 KB
/
slack.test.tsx
File metadata and controls
77 lines (70 loc) · 1.75 KB
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
import { notifyContactCreated, createPayload } from "../../helpers/slack";
const mockData = {
name: "Test name",
email: "test@test.com",
url: "https://www.test.dev/",
};
const mockBlocks = [
{
type: "header",
text: {
type: "plain_text",
text: "We have 1 new message(s).",
emoji: true,
},
},
{
type: "section",
text: {
type: "mrkdwn",
text: `We got a new message from _Test name_ (_test@test.com_).`,
},
},
{
type: "divider",
},
{
type: "section",
text: {
type: "mrkdwn",
text: " ",
},
accessory: {
type: "button",
text: {
type: "plain_text",
text: "Show me the message",
emoji: true,
},
value: "new_message_click",
url: "https://www.test.dev/",
action_id: "button-action",
},
},
];
describe("Slack helpers", () => {
describe("createPayload", () => {
it("should create expected payload", async () => {
const payload = createPayload(
mockData.name,
mockData.email,
mockData.url,
);
expect(payload.blocks).toEqual(mockBlocks);
});
});
describe("notifyContactCreated", () => {
it("should send message on slack with correct payload", async () => {
global.fetch = jest.fn().mockResolvedValue({
status: 200,
});
await notifyContactCreated(mockData.name, mockData.email, mockData.url);
const [[url, options]] = (global.fetch as jest.Mock).mock.calls;
const body = JSON.parse(options.body);
const blocks = JSON.stringify(body.blocks);
expect(url).toBe("https://slack.com/api/chat.postMessage");
expect(blocks).toMatch(JSON.stringify(mockBlocks));
expect(fetch).toHaveBeenCalledTimes(1);
});
});
});