@@ -99,4 +99,59 @@ describe('TokenProviderMiddleware', () => {
9999 ) . resolves . toMatchObject ( { } ) ;
100100 expect ( customFetch ) . toHaveBeenCalled ( ) ;
101101 } ) ;
102+
103+ it ( 'should use provided access token as a string' , async ( ) => {
104+ await expect ( tokenClient . testRequest ( { path : '/foo' , method : 'GET' } ) ) . resolves . toMatchObject (
105+ { }
106+ ) ;
107+ expect ( spy ) . toHaveBeenCalledWith (
108+ expect . objectContaining ( {
109+ authorization : 'Bearer token' ,
110+ } )
111+ ) ;
112+ } ) ;
113+
114+ it ( 'should use provided access token as a sync function' , async ( ) => {
115+ const syncTokenClient = new TestClient ( {
116+ ...opts ,
117+ middleware : [
118+ new TokenProviderMiddleware ( {
119+ ...opts ,
120+ domain,
121+ token : ( ) => 'sync-token' ,
122+ } ) ,
123+ ] ,
124+ } ) ;
125+
126+ await expect (
127+ syncTokenClient . testRequest ( { path : '/foo' , method : 'GET' } )
128+ ) . resolves . toMatchObject ( { } ) ;
129+ expect ( spy ) . toHaveBeenCalledWith (
130+ expect . objectContaining ( {
131+ authorization : 'Bearer sync-token' ,
132+ } )
133+ ) ;
134+ } ) ;
135+
136+ it ( 'should use provided access token as an async function' , async ( ) => {
137+ const asyncTokenClient = new TestClient ( {
138+ ...opts ,
139+ middleware : [
140+ new TokenProviderMiddleware ( {
141+ ...opts ,
142+ domain,
143+ token : async ( ) => 'async-token' ,
144+ } ) ,
145+ ] ,
146+ } ) ;
147+
148+ await expect (
149+ asyncTokenClient . testRequest ( { path : '/foo' , method : 'GET' } )
150+ ) . resolves . toMatchObject ( { } ) ;
151+ expect ( spy ) . toHaveBeenCalledWith (
152+ expect . objectContaining ( {
153+ authorization : 'Bearer async-token' ,
154+ } )
155+ ) ;
156+ } ) ;
102157} ) ;
0 commit comments