@@ -805,6 +805,58 @@ describe("Fetch AuthHttpRequest class tests with headers", function () {
805805 }
806806 } ) ;
807807
808+ it ( "test with fetch that attemptRefreshingSession is working correctly after removing st-access-token" , async function ( ) {
809+ await startST ( 5 ) ;
810+ const browser = await puppeteer . launch ( {
811+ args : [ "--no-sandbox" , "--disable-setuid-sandbox" ]
812+ } ) ;
813+ try {
814+ const page = await browser . newPage ( ) ;
815+ await page . goto ( BASE_URL + "/index.html" , { waitUntil : "load" } ) ;
816+ await page . addScriptTag ( { path : `./bundle/bundle.js` , type : "text/javascript" } ) ;
817+
818+ await page . evaluate ( async ( ) => {
819+ let BASE_URL = "http://localhost.org:8080" ;
820+ supertokens . init ( {
821+ apiDomain : BASE_URL ,
822+ tokenTransferMethod : "header"
823+ } ) ;
824+ let userId = "testing-supertokens-website" ;
825+ console . log ( "0" ) ;
826+
827+ // send api request to login
828+ let loginResponse = await fetch ( `${ BASE_URL } /login` , {
829+ method : "post" ,
830+ headers : {
831+ Accept : "application/json" ,
832+ "Content-Type" : "application/json"
833+ } ,
834+ body : JSON . stringify ( { userId } )
835+ } ) ;
836+ assertEqual ( await loginResponse . text ( ) , userId ) ;
837+
838+ document . cookie = "st-access-token=;expires=Thu, 01 Jan 1970 00:00:01 GMT" ;
839+
840+ let attemptRefresh = await supertokens . attemptRefreshingSession ( ) ;
841+ assertEqual ( attemptRefresh , true ) ;
842+
843+ //check that the number of times the refresh API was called is 1
844+ assertEqual ( await getNumberOfTimesRefreshCalled ( ) , 1 ) ;
845+
846+ let getSessionResponse = await fetch ( `${ BASE_URL } /` ) ;
847+ assertEqual ( await getSessionResponse . text ( ) , userId ) ;
848+
849+ //check that the number of times the refresh API was called is still 1
850+ assertEqual ( await getNumberOfTimesRefreshCalled ( ) , 1 ) ;
851+ } ) ;
852+
853+ const originalCookies = ( await page . _client . send ( "Network.getAllCookies" ) ) . cookies ;
854+ assert ( originalCookies . find ( c => c . name === "st-access-token" ) ) ;
855+ } finally {
856+ await browser . close ( ) ;
857+ }
858+ } ) ;
859+
808860 // multiple API calls in parallel when access token is expired (100 of them) and only 1 refresh should be called*****
809861 it ( "test with fetch that multiple API calls in parallel when access token is expired, only 1 refresh should be called" , async function ( ) {
810862 await startST ( 15 ) ;
0 commit comments