@@ -506,6 +506,9 @@ describe("OAuth Authorization", () => {
506506 access_token : "newaccess123" ,
507507 token_type : "Bearer" ,
508508 expires_in : 3600 ,
509+ }
510+ const validTokensWithNewRefreshToken = {
511+ ...validTokens ,
509512 refresh_token : "newrefresh123" ,
510513 } ;
511514
@@ -520,15 +523,15 @@ describe("OAuth Authorization", () => {
520523 mockFetch . mockResolvedValueOnce ( {
521524 ok : true ,
522525 status : 200 ,
523- json : async ( ) => validTokens ,
526+ json : async ( ) => validTokensWithNewRefreshToken ,
524527 } ) ;
525528
526529 const tokens = await refreshAuthorization ( "https://auth.example.com" , {
527530 clientInformation : validClientInfo ,
528531 refreshToken : "refresh123" ,
529532 } ) ;
530533
531- expect ( tokens ) . toEqual ( validTokens ) ;
534+ expect ( tokens ) . toEqual ( validTokensWithNewRefreshToken ) ;
532535 expect ( mockFetch ) . toHaveBeenCalledWith (
533536 expect . objectContaining ( {
534537 href : "https://auth.example.com/token" ,
@@ -548,6 +551,22 @@ describe("OAuth Authorization", () => {
548551 expect ( body . get ( "client_secret" ) ) . toBe ( "secret123" ) ;
549552 } ) ;
550553
554+ it ( "exchanges refresh token for new tokens and keep existing refresh token if none is returned" , async ( ) => {
555+ mockFetch . mockResolvedValueOnce ( {
556+ ok : true ,
557+ status : 200 ,
558+ json : async ( ) => validTokens ,
559+ } ) ;
560+
561+ const refreshToken = "refresh123" ;
562+ const tokens = await refreshAuthorization ( "https://auth.example.com" , {
563+ clientInformation : validClientInfo ,
564+ refreshToken,
565+ } ) ;
566+
567+ expect ( tokens ) . toEqual ( { refresh_token : refreshToken , ...validTokens } ) ;
568+ } ) ;
569+
551570 it ( "validates token response schema" , async ( ) => {
552571 mockFetch . mockResolvedValueOnce ( {
553572 ok : true ,
0 commit comments