@@ -9,6 +9,7 @@ describe("sendTaskUpdate function", () => {
9
9
const blockers = "No blockers" ;
10
10
const userName = "Tejas" ;
11
11
const taskId = "69nduIn210" ;
12
+ const taskTitle = "Hyperlink as task title" ;
12
13
const taskUrl = config ( mockEnv ) . RDS_STATUS_SITE_URL + `/tasks/${ taskId } ` ;
13
14
const assertFetchCall = ( url : string , bodyObj : any , mockEnv : any ) => {
14
15
expect ( global . fetch ) . toHaveBeenCalledWith ( url , {
@@ -24,11 +25,42 @@ describe("sendTaskUpdate function", () => {
24
25
afterEach ( ( ) => {
25
26
jest . clearAllMocks ( ) ;
26
27
} ) ;
28
+ test ( "should throw an error if response status is not OK" , async ( ) => {
29
+ const url = config ( mockEnv ) . TRACKING_CHANNEL_URL ;
30
+ const formattedString =
31
+ `**${ userName } ** added an update to their task: [${ taskTitle } ](<${ taskUrl } >)\n` +
32
+ `\n**Completed**\n${ completed } \n\n` +
33
+ `**Planned**\n${ planned } \n\n` +
34
+ `**Blockers**\n${ blockers } ` ;
35
+ const bodyObj = {
36
+ content : formattedString ,
37
+ } ;
38
+
39
+ jest
40
+ . spyOn ( global , "fetch" )
41
+ . mockResolvedValueOnce (
42
+ new JSONResponse ( "" , { status : 400 , statusText : "Bad Request" } )
43
+ ) ;
44
+
45
+ await expect (
46
+ sendTaskUpdate (
47
+ completed ,
48
+ planned ,
49
+ blockers ,
50
+ userName ,
51
+ taskId ,
52
+ taskTitle ,
53
+ mockEnv
54
+ )
55
+ ) . rejects . toThrowError ( "Failed to send task update: 400 - Bad Request" ) ;
56
+
57
+ assertFetchCall ( url , bodyObj , mockEnv ) ;
58
+ } ) ;
27
59
28
60
test ( "should send the task update to discord tracking channel when all fields are present" , async ( ) => {
29
61
const url = config ( mockEnv ) . TRACKING_CHANNEL_URL ;
30
62
const formattedString =
31
- `${ userName } added an update to their task: <${ taskUrl } >\n` +
63
+ `** ${ userName } ** added an update to their task: [ ${ taskTitle } ]( <${ taskUrl } >) \n` +
32
64
`\n**Completed**\n${ completed } \n\n` +
33
65
`**Planned**\n${ planned } \n\n` +
34
66
`**Blockers**\n${ blockers } ` ;
@@ -46,6 +78,7 @@ describe("sendTaskUpdate function", () => {
46
78
blockers ,
47
79
userName ,
48
80
taskId ,
81
+ taskTitle ,
49
82
mockEnv
50
83
) ;
51
84
@@ -55,7 +88,7 @@ describe("sendTaskUpdate function", () => {
55
88
test ( "should send the task update to discord tracking channel when only completed is present" , async ( ) => {
56
89
const url = config ( mockEnv ) . TRACKING_CHANNEL_URL ;
57
90
const formattedString =
58
- `${ userName } added an update to their task: <${ taskUrl } >\n` +
91
+ `** ${ userName } ** added an update to their task: [ ${ taskTitle } ]( <${ taskUrl } >) \n` +
59
92
`\n**Completed**\n${ completed } \n\n` +
60
93
`**Planned**\n\n\n` +
61
94
`**Blockers**\n` ;
@@ -67,15 +100,23 @@ describe("sendTaskUpdate function", () => {
67
100
. spyOn ( global , "fetch" )
68
101
. mockImplementation ( ( ) => Promise . resolve ( new JSONResponse ( "" ) ) ) ;
69
102
70
- await sendTaskUpdate ( completed , "" , "" , userName , taskId , mockEnv ) ;
103
+ await sendTaskUpdate (
104
+ completed ,
105
+ "" ,
106
+ "" ,
107
+ userName ,
108
+ taskId ,
109
+ taskTitle ,
110
+ mockEnv
111
+ ) ;
71
112
72
113
assertFetchCall ( url , bodyObj , mockEnv ) ;
73
114
} ) ;
74
115
75
116
test ( "should send the task update to discord tracking channel when only planned is present" , async ( ) => {
76
117
const url = config ( mockEnv ) . TRACKING_CHANNEL_URL ;
77
118
const formattedString =
78
- `${ userName } added an update to their task: <${ taskUrl } >\n` +
119
+ `** ${ userName } ** added an update to their task: [ ${ taskTitle } ]( <${ taskUrl } >) \n` +
79
120
`\n**Completed**\n\n\n` +
80
121
`**Planned**\n${ planned } \n\n` +
81
122
`**Blockers**\n` ;
@@ -87,15 +128,15 @@ describe("sendTaskUpdate function", () => {
87
128
. spyOn ( global , "fetch" )
88
129
. mockImplementation ( ( ) => Promise . resolve ( new JSONResponse ( "" ) ) ) ;
89
130
90
- await sendTaskUpdate ( "" , planned , "" , userName , taskId , mockEnv ) ;
131
+ await sendTaskUpdate ( "" , planned , "" , userName , taskId , taskTitle , mockEnv ) ;
91
132
92
133
assertFetchCall ( url , bodyObj , mockEnv ) ;
93
134
} ) ;
94
135
95
136
test ( "should send the task update to discord tracking channel when only blockers is present" , async ( ) => {
96
137
const url = config ( mockEnv ) . TRACKING_CHANNEL_URL ;
97
138
const formattedString =
98
- `${ userName } added an update to their task: <${ taskUrl } >\n` +
139
+ `** ${ userName } ** added an update to their task: [ ${ taskTitle } ]( <${ taskUrl } >) \n` +
99
140
`\n**Completed**\n\n\n` +
100
141
`**Planned**\n\n\n` +
101
142
`**Blockers**\n${ blockers } ` ;
@@ -107,15 +148,23 @@ describe("sendTaskUpdate function", () => {
107
148
. spyOn ( global , "fetch" )
108
149
. mockImplementation ( ( ) => Promise . resolve ( new JSONResponse ( "" ) ) ) ;
109
150
110
- await sendTaskUpdate ( "" , "" , blockers , userName , taskId , mockEnv ) ;
151
+ await sendTaskUpdate (
152
+ "" ,
153
+ "" ,
154
+ blockers ,
155
+ userName ,
156
+ taskId ,
157
+ taskTitle ,
158
+ mockEnv
159
+ ) ;
111
160
112
161
assertFetchCall ( url , bodyObj , mockEnv ) ;
113
162
} ) ;
114
163
115
164
test ( "should send the task update to discord tracking channel when only completed and planned are present" , async ( ) => {
116
165
const url = config ( mockEnv ) . TRACKING_CHANNEL_URL ;
117
166
const formattedString =
118
- `${ userName } added an update to their task: <${ taskUrl } >\n` +
167
+ `** ${ userName } ** added an update to their task: [ ${ taskTitle } ]( <${ taskUrl } >) \n` +
119
168
`\n**Completed**\n${ completed } \n\n` +
120
169
`**Planned**\n${ planned } \n\n` +
121
170
`**Blockers**\n` ;
@@ -127,15 +176,23 @@ describe("sendTaskUpdate function", () => {
127
176
. spyOn ( global , "fetch" )
128
177
. mockImplementation ( ( ) => Promise . resolve ( new JSONResponse ( "" ) ) ) ;
129
178
130
- await sendTaskUpdate ( completed , planned , "" , userName , taskId , mockEnv ) ;
179
+ await sendTaskUpdate (
180
+ completed ,
181
+ planned ,
182
+ "" ,
183
+ userName ,
184
+ taskId ,
185
+ taskTitle ,
186
+ mockEnv
187
+ ) ;
131
188
132
189
assertFetchCall ( url , bodyObj , mockEnv ) ;
133
190
} ) ;
134
191
135
192
test ( "should send the task update to discord tracking channel when only completed and blockers are present" , async ( ) => {
136
193
const url = config ( mockEnv ) . TRACKING_CHANNEL_URL ;
137
194
const formattedString =
138
- `${ userName } added an update to their task: <${ taskUrl } >\n` +
195
+ `** ${ userName } ** added an update to their task: [ ${ taskTitle } ]( <${ taskUrl } >) \n` +
139
196
`\n**Completed**\n${ completed } \n\n` +
140
197
`**Planned**\n\n\n` +
141
198
`**Blockers**\n${ blockers } ` ;
@@ -147,15 +204,23 @@ describe("sendTaskUpdate function", () => {
147
204
. spyOn ( global , "fetch" )
148
205
. mockImplementation ( ( ) => Promise . resolve ( new JSONResponse ( "" ) ) ) ;
149
206
150
- await sendTaskUpdate ( completed , "" , blockers , userName , taskId , mockEnv ) ;
207
+ await sendTaskUpdate (
208
+ completed ,
209
+ "" ,
210
+ blockers ,
211
+ userName ,
212
+ taskId ,
213
+ taskTitle ,
214
+ mockEnv
215
+ ) ;
151
216
152
217
assertFetchCall ( url , bodyObj , mockEnv ) ;
153
218
} ) ;
154
219
155
220
test ( "should send the task update to discord tracking channel when only planned and blockers are present" , async ( ) => {
156
221
const url = config ( mockEnv ) . TRACKING_CHANNEL_URL ;
157
222
const formattedString =
158
- `${ userName } added an update to their task: <${ taskUrl } >\n` +
223
+ `** ${ userName } ** added an update to their task: [ ${ taskTitle } ]( <${ taskUrl } >) \n` +
159
224
`\n**Completed**\n\n\n` +
160
225
`**Planned**\n${ planned } \n\n` +
161
226
`**Blockers**\n${ blockers } ` ;
@@ -167,7 +232,15 @@ describe("sendTaskUpdate function", () => {
167
232
. spyOn ( global , "fetch" )
168
233
. mockImplementation ( ( ) => Promise . resolve ( new JSONResponse ( "" ) ) ) ;
169
234
170
- await sendTaskUpdate ( "" , planned , blockers , userName , taskId , mockEnv ) ;
235
+ await sendTaskUpdate (
236
+ "" ,
237
+ planned ,
238
+ blockers ,
239
+ userName ,
240
+ taskId ,
241
+ taskTitle ,
242
+ mockEnv
243
+ ) ;
171
244
172
245
assertFetchCall ( url , bodyObj , mockEnv ) ;
173
246
} ) ;
0 commit comments