@@ -8,6 +8,17 @@ describe("sendTaskUpdate function", () => {
8
8
const planned = "Plan for the next phase" ;
9
9
const blockers = "No blockers" ;
10
10
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
+
11
22
afterEach ( ( ) => {
12
23
jest . clearAllMocks ( ) ;
13
24
} ) ;
@@ -25,14 +36,7 @@ describe("sendTaskUpdate function", () => {
25
36
26
37
await sendTaskUpdate ( completed , planned , blockers , mockEnv ) ;
27
38
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 ) ;
36
40
} ) ;
37
41
38
42
test ( "should send the task update to discord tracking channel when only completed is present" , async ( ) => {
@@ -48,14 +52,7 @@ describe("sendTaskUpdate function", () => {
48
52
49
53
await sendTaskUpdate ( completed , "" , "" , mockEnv ) ;
50
54
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 ) ;
59
56
} ) ;
60
57
61
58
test ( "should send the task update to discord tracking channel when only planned is present" , async ( ) => {
@@ -71,14 +68,7 @@ describe("sendTaskUpdate function", () => {
71
68
72
69
await sendTaskUpdate ( "" , planned , "" , mockEnv ) ;
73
70
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 ) ;
82
72
} ) ;
83
73
84
74
test ( "should send the task update to discord tracking channel when only blockers is present" , async ( ) => {
@@ -94,14 +84,7 @@ describe("sendTaskUpdate function", () => {
94
84
95
85
await sendTaskUpdate ( "" , "" , blockers , mockEnv ) ;
96
86
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 ) ;
105
88
} ) ;
106
89
107
90
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", () => {
117
100
118
101
await sendTaskUpdate ( completed , planned , "" , mockEnv ) ;
119
102
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 ) ;
128
104
} ) ;
129
105
130
106
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", () => {
140
116
141
117
await sendTaskUpdate ( completed , "" , blockers , mockEnv ) ;
142
118
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 ) ;
151
120
} ) ;
152
121
153
122
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", () => {
163
132
164
133
await sendTaskUpdate ( "" , planned , blockers , mockEnv ) ;
165
134
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 ) ;
174
136
} ) ;
175
137
} ) ;
0 commit comments