@@ -10,6 +10,7 @@ const credentials = require('../../../env');
10
10
const chai = require ( 'chai' ) ;
11
11
chai . use ( require ( 'sinon-chai' ) ) ;
12
12
const assert = chai . assert ;
13
+ const expect = chai . expect ;
13
14
14
15
describe ( 'Outbound Voice Task' , ( ) => {
15
16
const aliceToken = getAccessToken ( credentials . accountSid , credentials . multiTaskWorkspaceSid , credentials . multiTaskAliceSid ) ;
@@ -176,15 +177,15 @@ describe('Outbound Voice Task', () => {
176
177
await aliceReservation . task . hold ( credentials . multiTaskBobSid , true ) ;
177
178
reject ( 'Failed to throw 400 on request to hold worker B' ) ;
178
179
} catch ( err ) {
179
- assert . strictEqual ( err . response . status , 400 , 'Task on-hold request failure error code' ) ;
180
+ expect ( err . toString ( ) ) . contain ( ' status code 400' , 'Task on-hold request failure error code' ) ; ;
180
181
}
181
182
182
183
// Worker B tries to put worker A on hold
183
184
try {
184
185
await bobReservation . task . hold ( credentials . multiTaskAliceSid , true ) ;
185
186
reject ( 'Failed to throw 400 on request to hold worker A' ) ;
186
187
} catch ( err ) {
187
- assert . strictEqual ( err . response . status , 400 , 'Task on-hold request failure error code' ) ;
188
+ expect ( err . toString ( ) ) . contain ( ' status code 400' , 'Task on-hold request failure error code' ) ;
188
189
}
189
190
resolve ( 'Outbound test fail if worker A put worker B (and vice versa) on hold if they are not in same conference' ) ;
190
191
} catch ( err ) {
@@ -219,15 +220,15 @@ describe('Outbound Voice Task', () => {
219
220
await aliceReservation . task . hold ( credentials . multiTaskBobSid , true ) ;
220
221
reject ( 'Failed to throw 400 on request to hold worker B' ) ;
221
222
} catch ( err ) {
222
- assert . strictEqual ( err . response . status , 400 , 'Task on-hold request failure error code' ) ;
223
+ expect ( err . toString ( ) ) . contain ( ' status code 400' , 'Task on-hold request failure error code' ) ;
223
224
}
224
225
225
226
// Worker B tries to put worker A on hold
226
227
try {
227
228
await bobReservation . task . hold ( credentials . multiTaskAliceSid , true ) ;
228
229
reject ( 'Failed to throw 400 on request to hold worker A' ) ;
229
230
} catch ( err ) {
230
- assert . strictEqual ( err . response . status , 400 , 'Task on-hold request failure error code' ) ;
231
+ expect ( err . toString ( ) ) . contain ( ' status code 400' , 'Task on-hold request failure error code' ) ;
231
232
resolve ( 'Outbound test to fail when worker A puts worker B (and vice-versa) on hold if reservation of worker B is pending' ) ;
232
233
}
233
234
} catch ( err ) {
@@ -246,38 +247,37 @@ describe('Outbound Voice Task', () => {
246
247
it ( 'should throw a validation error when using an incorrect workflow sid' , ( ) => {
247
248
return new Promise ( async ( resolve , reject ) => {
248
249
// eslint-disable-next-line
249
- const expected = `Value \'${ credentials . multiTaskWorkflowSid } z\' provided for` +
250
- ' WorkflowSid has an invalid format' ;
250
+ const expectedDownstreamStatusText = `Value \'${ credentials . multiTaskWorkflowSid } z\' provided for` +
251
+ ' WorkflowSid has an invalid format' ;
252
+ const expectedErrorMessage = `Request failed with status code 400. ${ expectedDownstreamStatusText } `
251
253
try {
252
254
253
255
await alice . createTask ( credentials . customerNumber , credentials . flexCCNumber ,
254
- credentials . multiTaskWorkflowSid , credentials . multiTaskQueueSid ) ;
256
+ credentials . multiTaskWorkflowSid , credentials . multiTaskQueueSid ) ;
255
257
256
258
await alice . createTask ( credentials . customerNumber , credentials . flexCCNumber ,
257
- credentials . multiTaskWorkflowSid + 'z' , credentials . multiTaskQueueSid ) ;
259
+ credentials . multiTaskWorkflowSid + 'z' , credentials . multiTaskQueueSid ) ;
258
260
reject ( 'Invalid WorkflowSid should be rejected' ) ;
259
261
} catch ( err ) {
260
- assert . strictEqual ( err . response . status , 400 , 'expecting a bad request' ) ;
261
- assert . strictEqual ( err . response . statusText , expected ,
262
- 'Got a different validation failure than expected' ) ;
262
+ assert . strictEqual ( err . message , expectedErrorMessage ,
263
+ 'Got a different validation failure than expected' ) ;
263
264
resolve ( 'Test for validation error when using an incorrect workflowSid finished' ) ;
264
265
}
265
266
} ) ;
266
267
} ) . timeout ( 5000 ) ;
267
268
268
269
it ( 'should throw a validation error when using an incorrect queue sid' , ( ) => {
269
270
return new Promise ( async ( resolve , reject ) => {
271
+ let expectedErrorMessage = 'Request failed with status code 400. HTTP 400 Bad Request' ;
270
272
try {
271
273
await alice . createTask ( credentials . customerNumber , credentials . flexCCNumber ,
272
- credentials . multiTaskWorkflowSid , credentials . multiTaskQueueSid + 'z' ) ;
274
+ credentials . multiTaskWorkflowSid , credentials . multiTaskQueueSid + 'z' ) ;
273
275
reject ( 'Invalid QueueSid should be rejected' ) ;
274
276
} catch ( err ) {
275
- assert . strictEqual ( err . response . status , 400 , 'expecting a bad request' ) ;
276
- // taskrouter doesn't send a validation message here
277
+ assert . strictEqual ( err . message , expectedErrorMessage , 'expecting a bad request' ) ;
277
278
resolve ( 'Test for validation error when using an incorrect QueueSid finished' ) ;
278
279
}
279
280
} ) ;
280
281
} ) . timeout ( 5000 ) ;
281
282
} ) ;
282
- } ) ;
283
-
283
+ } ) ;
0 commit comments