@@ -23,19 +23,48 @@ const BadExecution = require("./badExecution.js");
2323describe ( 'bad execution' , function ( ) {
2424 const service = BadExecution . on ( testutil . makeClient ( ) ) ;
2525
26- it ( 'error mapping' , function ( done ) {
27- service . errorMapping ( )
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+ ] ;
34+
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 ;
46+
47+ service . errorMapping ( sentCode , sentMsg )
2848 . then ( output => {
2949 expect . fail ( 'should not succeed' ) ;
3050 done ( ) ;
3151 } )
3252 . catch ( err => {
3353 const errorResponse = err . body . errorResponse ;
34- expect ( errorResponse . statusCode ) . to . eql ( 418 ) ;
35- expect ( errorResponse . status ) . to . eql ( "Status Message For 418" ) ;
36- expect ( errorResponse . messageCode ) . to . eql ( 'ERROR_MAPPING' ) ;
37- expect ( errorResponse . message ) . to . contain ( 'Test of error mapping' ) ;
38- done ( ) ;
54+ // console.log(errorResponse);
55+ expect ( errorResponse . statusCode ) . to . eql ( statusCode ) ;
56+ expect ( errorResponse . status ) . to . eql ( mappedMsg ) ;
57+ expect ( errorResponse . messageCode ) . to . eql ( mappedCode ) ;
58+ if ( sentMsg !== null ) {
59+ const inlineMsg = ': fn.error(null, errCode, errMsg); -- ' ;
60+ const msgOffset = errorResponse . message . indexOf ( inlineMsg ) + inlineMsg . length ;
61+ expect ( errorResponse . message . substring ( msgOffset , msgOffset + sentMsg . length ) ) . to . eql ( sentMsg ) ;
62+ }
63+ runTest ( i + 1 , done ) ;
3964 } ) ;
65+ }
66+
67+ it ( 'error conditions' , function ( done ) {
68+ runTest ( 0 , done ) ;
4069 } ) ;
4170} ) ;
0 commit comments