import AppTokenHolder from "../../../src/github/client/app-token-holder" ; import { getCloudInstallationId } from "../../../src/github/client/installation-id" ; describe ( "AppTokenHolder" , ( ) => { beforeAll ( ( ) => { jest . useFakeTimers ( "modern" ) ; } ) ; afterAll ( ( ) => { jest . useRealTimers ( ) ; } ) ; it ( "Re-generates expired tokens" , async ( ) => { const appTokenHolder = new AppTokenHolder ( ) ; jest . setSystemTime ( new Date ( 2021 , 10 , 25 , 10 , 0 ) ) ; const token1 = appTokenHolder . getAppToken ( getCloudInstallationId ( 4711 ) ) ; expect ( token1 ) . toBeTruthy ( ) ; jest . setSystemTime ( new Date ( 2021 , 10 , 25 , 10 , 5 ) ) ; const token2 = appTokenHolder . getAppToken ( getCloudInstallationId ( 4711 ) ) ; expect ( token2 ) . toEqual ( token1 ) ; jest . setSystemTime ( new Date ( 2021 , 10 , 25 , 10 , 10 ) ) ; const token3 = appTokenHolder . getAppToken ( getCloudInstallationId ( 4711 ) ) ; expect ( token3 ) . not . toEqual ( token1 ) ; } ) ; } ) ;