@@ -101,16 +101,38 @@ describe('AuthenticateHandler integration', function() {
101101 } ) ;
102102
103103 describe ( 'handle()' , function ( ) {
104- it ( 'should throw an error if `request` is missing' , async function ( ) {
105- const handler = new AuthenticateHandler ( { model : { getAccessToken : function ( ) { } } } ) ;
104+ it ( 'should throw an error if `request` is missing or not a Request instance' , async function ( ) {
105+ class Request { } // intentionally fake
106+ const values = [ undefined , null , { } , [ ] , new Date ( ) , new Request ( ) ] ;
107+ for ( const request of values ) {
108+ const handler = new AuthenticateHandler ( { model : { getAccessToken : function ( ) { } } } ) ;
109+
110+ try {
111+ await handler . handle ( request ) ;
112+
113+ should . fail ( ) ;
114+ } catch ( e ) {
115+ e . should . be . an . instanceOf ( InvalidArgumentError ) ;
116+ e . message . should . equal ( 'Invalid argument: `request` must be an instance of Request' ) ;
117+ }
118+ }
119+ } ) ;
106120
107- try {
108- await handler . handle ( ) ;
121+ it ( 'should throw an error if `response` is missing or not a Response instance' , async function ( ) {
122+ class Response { } // intentionally fake
123+ const values = [ undefined , null , { } , [ ] , new Date ( ) , new Response ( ) ] ;
124+ const request = new Request ( { body : { } , headers : { 'Authorization' : 'Bearer foo' } , method : { } , query : { } } ) ;
109125
110- should . fail ( ) ;
111- } catch ( e ) {
112- e . should . be . an . instanceOf ( InvalidArgumentError ) ;
113- e . message . should . equal ( 'Invalid argument: `request` must be an instance of Request' ) ;
126+ for ( const response of values ) {
127+ const handler = new AuthenticateHandler ( { model : { getAccessToken : function ( ) { } } } ) ;
128+ try {
129+ await handler . handle ( request , response ) ;
130+
131+ should . fail ( ) ;
132+ } catch ( e ) {
133+ e . should . be . an . instanceOf ( InvalidArgumentError ) ;
134+ e . message . should . equal ( 'Invalid argument: `response` must be an instance of Response' ) ;
135+ }
114136 }
115137 } ) ;
116138
0 commit comments