File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,18 @@ class Test extends Request {
187187 fn . call ( this , errorObj || null , res ) ;
188188 }
189189
190+ /*
191+ * Adds a set Authorization Bearer
192+ *
193+ * @param {Bearer } Bearer Token
194+ * Shortcut for .set('Authorization', `Bearer ${token}`)
195+ */
196+
197+ bearer ( token ) {
198+ this . set ( 'Authorization' , `Bearer ${ token } ` ) ;
199+ return this ;
200+ }
201+
190202 /**
191203 * Perform assertions on a response body and return an Error upon failure.
192204 *
Original file line number Diff line number Diff line change @@ -233,6 +233,23 @@ describe('request(app)', function () {
233233 } ) ;
234234 } ) ;
235235
236+ describe ( '.bearer(token)' , function ( ) {
237+ it ( 'should work the bearer token' , function ( ) {
238+ const app = express ( ) ;
239+ const test = request ( app ) ;
240+
241+ app . get ( '/' , function ( req , res ) {
242+ if ( req . headers . authorization === 'Bearer test-token' ) {
243+ res . status ( 200 ) . send ( 'Authorized' ) ;
244+ } else {
245+ res . status ( 403 ) . send ( 'Unauthorized' ) ;
246+ }
247+ } ) ;
248+
249+ test . get ( '/' ) . bearer ( 'test-token' ) . expect ( 200 ) . expect ( 'Authoried' ) ;
250+ } ) ;
251+ } ) ;
252+
236253 describe ( '.end(fn)' , function ( ) {
237254 it ( 'should close server' , function ( done ) {
238255 const app = express ( ) ;
You can’t perform that action at this time.
0 commit comments