@@ -23,12 +23,16 @@ describe('interceptor', function() {
2323 } ) ;
2424 } ) ;
2525
26- it ( 'should cache the oauth access token until it expires' , function ( done ) {
26+ it ( 'should cache the oauth access token until it expires' , async function ( ) {
27+ function delay ( ms ) {
28+ return new Promise ( ( resolve , reject ) => setTimeout ( resolve , ms ) ) ;
29+ }
30+
2731 let calls = 0 ;
2832 const authenticate = async ( ) => {
2933 return {
3034 access_token : 'foo' + calls ++ ,
31- expires_in : 1
35+ expires_in : 2
3236 }
3337 } ;
3438
@@ -43,27 +47,23 @@ describe('interceptor', function() {
4347 ] )
4448 }
4549
46- function delay ( ms ) {
47- return new Promise ( ( resolve , reject ) => setTimeout ( resolve , ms ) ) ;
48- }
49-
5050 function verify ( results , expected ) {
5151 for ( let result of results ) {
5252 assert . deepEqual ( result , expected ) ;
5353 }
5454 }
5555
56- test3x ( req )
57- . then ( results => verify ( results , {
58- headers : { Authorization : 'Bearer foo0' }
59- } ) )
60- . then ( ( ) => delay ( 1500 ) )
61- . then ( ( ) => test3x ( req ) )
62- . then ( results => verify ( results , {
63- headers : { Authorization : 'Bearer foo1' }
64- } ) )
65- . then ( ( ) => done ( ) )
66- . catch ( done ) ;
56+ let results = await test3x ( req ) ;
57+ verify ( results , {
58+ headers : { Authorization : 'Bearer foo0' }
59+ } ) ;
60+
61+ await delay ( 3000 ) ;
62+
63+ results = await test3x ( req ) ;
64+ verify ( results , {
65+ headers : { Authorization : 'Bearer foo1' }
66+ } ) ;
6767 } ) ;
6868 } ) ;
6969} ) ;
0 commit comments