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 @@ -172,6 +172,18 @@ class Test extends Request {
172172 fn . call ( this , errorObj || null , res ) ;
173173 }
174174
175+ /*
176+ * Adds a set Authorization Bearer
177+ *
178+ * @param {Bearer } Bearer Token
179+ * Shortcut for .set('Authorization', `Bearer ${token}`)
180+ */
181+
182+ bearer ( token ) {
183+ this . set ( 'Authorization' , `Bearer ${ token } ` ) ;
184+ return this ;
185+ }
186+
175187 /**
176188 * Perform assertions on a response body and return an Error upon failure.
177189 *
Original file line number Diff line number Diff line change @@ -216,6 +216,23 @@ describe('request(app)', function () {
216216 } ) ;
217217 } ) ;
218218
219+ describe ( '.bearer(token)' , function ( ) {
220+ it ( 'should work the bearer token' , function ( ) {
221+ const app = express ( ) ;
222+ const test = request ( app ) ;
223+
224+ app . get ( '/' , function ( req , res ) {
225+ if ( req . headers . authorization === 'Bearer test-token' ) {
226+ res . status ( 200 ) . send ( 'Authorized' ) ;
227+ } else {
228+ res . status ( 403 ) . send ( 'Unauthorized' ) ;
229+ }
230+ } ) ;
231+
232+ test . get ( '/' ) . bearer ( 'test-token' ) . expect ( 200 ) . expect ( 'Authoried' ) ;
233+ } ) ;
234+ } ) ;
235+
219236 describe ( '.end(fn)' , function ( ) {
220237 it ( 'should close server' , function ( done ) {
221238 const app = express ( ) ;
You can’t perform that action at this time.
0 commit comments