Skip to content

Commit bee81df

Browse files
committed
refactor: add a assert function
1 parent e9f6aff commit bee81df

File tree

1 file changed

+18
-56
lines changed

1 file changed

+18
-56
lines changed

tests/unit/utils/sendTasksUpdates.test.ts

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ describe("sendTaskUpdate function", () => {
88
const planned = "Plan for the next phase";
99
const blockers = "No blockers";
1010

11+
const assertFetchCall = (url: string, bodyObj: any, mockEnv: any) => {
12+
expect(global.fetch).toHaveBeenCalledWith(url, {
13+
method: "POST",
14+
headers: {
15+
"Content-Type": "application/json",
16+
Authorization: `Bot ${mockEnv.DISCORD_TOKEN}`,
17+
},
18+
body: JSON.stringify(bodyObj),
19+
});
20+
};
21+
1122
afterEach(() => {
1223
jest.clearAllMocks();
1324
});
@@ -25,14 +36,7 @@ describe("sendTaskUpdate function", () => {
2536

2637
await sendTaskUpdate(completed, planned, blockers, mockEnv);
2738

28-
expect(global.fetch).toHaveBeenCalledWith(url, {
29-
method: "POST",
30-
headers: {
31-
"Content-Type": "application/json",
32-
Authorization: `Bot ${mockEnv.DISCORD_TOKEN}`,
33-
},
34-
body: JSON.stringify(bodyObj),
35-
});
39+
assertFetchCall(url, bodyObj, mockEnv);
3640
});
3741

3842
test("should send the task update to discord tracking channel when only completed is present", async () => {
@@ -48,14 +52,7 @@ describe("sendTaskUpdate function", () => {
4852

4953
await sendTaskUpdate(completed, "", "", mockEnv);
5054

51-
expect(global.fetch).toHaveBeenCalledWith(url, {
52-
method: "POST",
53-
headers: {
54-
"Content-Type": "application/json",
55-
Authorization: `Bot ${mockEnv.DISCORD_TOKEN}`,
56-
},
57-
body: JSON.stringify(bodyObj),
58-
});
55+
assertFetchCall(url, bodyObj, mockEnv);
5956
});
6057

6158
test("should send the task update to discord tracking channel when only planned is present", async () => {
@@ -71,14 +68,7 @@ describe("sendTaskUpdate function", () => {
7168

7269
await sendTaskUpdate("", planned, "", mockEnv);
7370

74-
expect(global.fetch).toHaveBeenCalledWith(url, {
75-
method: "POST",
76-
headers: {
77-
"Content-Type": "application/json",
78-
Authorization: `Bot ${mockEnv.DISCORD_TOKEN}`,
79-
},
80-
body: JSON.stringify(bodyObj),
81-
});
71+
assertFetchCall(url, bodyObj, mockEnv);
8272
});
8373

8474
test("should send the task update to discord tracking channel when only blockers is present", async () => {
@@ -94,14 +84,7 @@ describe("sendTaskUpdate function", () => {
9484

9585
await sendTaskUpdate("", "", blockers, mockEnv);
9686

97-
expect(global.fetch).toHaveBeenCalledWith(url, {
98-
method: "POST",
99-
headers: {
100-
"Content-Type": "application/json",
101-
Authorization: `Bot ${mockEnv.DISCORD_TOKEN}`,
102-
},
103-
body: JSON.stringify(bodyObj),
104-
});
87+
assertFetchCall(url, bodyObj, mockEnv);
10588
});
10689

10790
test("should send the task update to discord tracking channel when only completed and planned are present", async () => {
@@ -117,14 +100,7 @@ describe("sendTaskUpdate function", () => {
117100

118101
await sendTaskUpdate(completed, planned, "", mockEnv);
119102

120-
expect(global.fetch).toHaveBeenCalledWith(url, {
121-
method: "POST",
122-
headers: {
123-
"Content-Type": "application/json",
124-
Authorization: `Bot ${mockEnv.DISCORD_TOKEN}`,
125-
},
126-
body: JSON.stringify(bodyObj),
127-
});
103+
assertFetchCall(url, bodyObj, mockEnv);
128104
});
129105

130106
test("should send the task update to discord tracking channel when only completed and blockers are present", async () => {
@@ -140,14 +116,7 @@ describe("sendTaskUpdate function", () => {
140116

141117
await sendTaskUpdate(completed, "", blockers, mockEnv);
142118

143-
expect(global.fetch).toHaveBeenCalledWith(url, {
144-
method: "POST",
145-
headers: {
146-
"Content-Type": "application/json",
147-
Authorization: `Bot ${mockEnv.DISCORD_TOKEN}`,
148-
},
149-
body: JSON.stringify(bodyObj),
150-
});
119+
assertFetchCall(url, bodyObj, mockEnv);
151120
});
152121

153122
test("should send the task update to discord tracking channel when only planned and blockers are present", async () => {
@@ -163,13 +132,6 @@ describe("sendTaskUpdate function", () => {
163132

164133
await sendTaskUpdate("", planned, blockers, mockEnv);
165134

166-
expect(global.fetch).toHaveBeenCalledWith(url, {
167-
method: "POST",
168-
headers: {
169-
"Content-Type": "application/json",
170-
Authorization: `Bot ${mockEnv.DISCORD_TOKEN}`,
171-
},
172-
body: JSON.stringify(bodyObj),
173-
});
135+
assertFetchCall(url, bodyObj, mockEnv);
174136
});
175137
});

0 commit comments

Comments
 (0)