@@ -23,26 +23,14 @@ const BadExecution = require("./badExecution.js");
2323describe ( 'bad execution' , function ( ) {
2424 const service = BadExecution . on ( testutil . makeClient ( ) ) ;
2525
26- const test = [
27- [ 406 , 'Unacceptable1' , "Unacceptable in every way" ] ,
28- [ 406 , 'Unacceptable2' , "Unacceptable, that's how you'll stay" , "Unacceptable, that's how you'll stay" ] ,
29- [ 406 , 'Unacceptable2' , "Unacceptable, that's how you'll stay" , null ] ,
30- [ 406 , 'Unacceptable2' , "Unacceptable, that's how you'll stay" , "Unacceptable no matter how near or far" ] ,
31- [ 410 , 'Absent1' , "You may search this wide world over" ] ,
32- [ 500 , 'Unknown1' , null , "Are the stars out tonight?" ]
33- ] ;
26+ function runTest ( expecteds , i , done ) {
27+ const expected = expecteds [ i ] ;
3428
35- function runTest ( i , done ) {
36- if ( i === test . length ) {
37- done ( ) ;
38- }
39- const testCase = test [ i ] ;
40-
41- const statusCode = testCase [ 0 ] ;
42- const sentCode = testCase [ 1 ] ;
43- const mappedMsg = ( testCase [ 2 ] === null ) ? 'Internal Server Error' : testCase [ 2 ] ;
44- const sentMsg = ( testCase . length < 4 ) ? null : testCase [ 3 ] ;
45- const mappedCode = ( testCase [ 2 ] === null ) ? 'INTERNAL ERROR' : sentCode ;
29+ const statusCode = expected [ 0 ] ;
30+ const sentCode = expected [ 1 ] ;
31+ const mappedMsg = ( expected [ 2 ] === null ) ? 'Internal Server Error' : expected [ 2 ] ;
32+ const sentMsg = ( expected . length < 4 ) ? null : expected [ 3 ] ;
33+ const mappedCode = ( expected [ 2 ] === null ) ? 'INTERNAL ERROR' : sentCode ;
4634
4735 service . errorMapping ( sentCode , sentMsg )
4836 . then ( output => {
@@ -60,11 +48,24 @@ describe('bad execution', function() {
6048 const msgOffset = errorResponse . message . indexOf ( inlineMsg ) + inlineMsg . length ;
6149 expect ( errorResponse . message . substring ( msgOffset , msgOffset + sentMsg . length ) ) . to . eql ( sentMsg ) ;
6250 }
63- runTest ( i + 1 , done ) ;
51+ i ++ ;
52+ if ( i < expecteds . length ) {
53+ runTest ( expecteds , i , done ) ;
54+ } else {
55+ done ( ) ;
56+ }
6457 } ) ;
6558 }
6659
6760 it ( 'error conditions' , function ( done ) {
68- runTest ( 0 , done ) ;
61+ const expecteds = [
62+ [ 406 , 'Unacceptable1' , "Unacceptable in every way" ] ,
63+ [ 406 , 'Unacceptable2' , "Unacceptable, that's how you'll stay" , "Unacceptable, that's how you'll stay" ] ,
64+ [ 406 , 'Unacceptable2' , "Unacceptable, that's how you'll stay" , null ] ,
65+ [ 406 , 'Unacceptable2' , "Unacceptable, that's how you'll stay" , "Unacceptable no matter how near or far" ] ,
66+ [ 410 , 'Absent1' , "You may search this wide world over" ] ,
67+ [ 500 , 'Unknown1' , null , "Are the stars out tonight?" ]
68+ ] ;
69+ runTest ( expecteds , 0 , done ) ;
6970 } ) ;
7071} ) ;
0 commit comments