1
1
import { InstallationTokenCache } from "./installation-token-cache" ;
2
- import { AuthToken , ONE_MINUTE , TEN_MINUTES } from "./auth-token" ;
2
+ import { AuthToken , ONE_MINUTE , NINE_MINUTES_MSEC } from "./auth-token" ;
3
3
4
4
jest . unmock ( "lru-cache" ) ;
5
5
6
6
describe ( "InstallationTokenCache" , ( ) => {
7
7
8
8
const now = new Date ( 2021 , 10 , 25 , 10 , 0 ) ;
9
9
const in5Minutes = new Date ( now . getTime ( ) + 5 * ONE_MINUTE ) ;
10
- const in10Minutes = new Date ( now . getTime ( ) + TEN_MINUTES ) ;
11
- const in20Minutes = new Date ( now . getTime ( ) + 2 * TEN_MINUTES ) ;
10
+ const in9Minutes = new Date ( now . getTime ( ) + NINE_MINUTES_MSEC ) ;
11
+ const in18Minutes = new Date ( now . getTime ( ) + 2 * NINE_MINUTES_MSEC ) ;
12
12
13
13
beforeAll ( ( ) => {
14
14
jest . useFakeTimers ( "modern" ) ;
@@ -22,8 +22,8 @@ describe("InstallationTokenCache", () => {
22
22
23
23
const GITHUB_INSTALLATION_ID = 1 ;
24
24
jest . setSystemTime ( now ) ;
25
- const token1 = new AuthToken ( "token1" , in10Minutes ) ;
26
- const token2 = new AuthToken ( "token2" , in10Minutes ) ;
25
+ const token1 = new AuthToken ( "token1" , in9Minutes ) ;
26
+ const token2 = new AuthToken ( "token2" , in9Minutes ) ;
27
27
28
28
const cache1 = InstallationTokenCache . getInstance ( ) ;
29
29
const cache2 = InstallationTokenCache . getInstance ( ) ;
@@ -40,8 +40,8 @@ describe("InstallationTokenCache", () => {
40
40
const GITHUB_INSTALLATION_ID = 1 ;
41
41
const GITHUB_APP_ID = 1 ;
42
42
jest . setSystemTime ( now ) ;
43
- const token1 = new AuthToken ( "token1" , in10Minutes ) ;
44
- const token2 = new AuthToken ( "token2" , in10Minutes ) ;
43
+ const token1 = new AuthToken ( "token1" , in9Minutes ) ;
44
+ const token2 = new AuthToken ( "token2" , in9Minutes ) ;
45
45
46
46
const cache1 = InstallationTokenCache . getInstance ( ) ;
47
47
const cache2 = InstallationTokenCache . getInstance ( ) ;
@@ -58,8 +58,8 @@ describe("InstallationTokenCache", () => {
58
58
const GITHUB_INSTALLATION_ID_1 = 21 ;
59
59
const GITHUB_INSTALLATION_ID_2 = 22 ;
60
60
jest . setSystemTime ( now ) ;
61
- const token1 = new AuthToken ( "token1" , in10Minutes ) ;
62
- const token2 = new AuthToken ( "token2" , in10Minutes ) ;
61
+ const token1 = new AuthToken ( "token1" , in9Minutes ) ;
62
+ const token2 = new AuthToken ( "token2" , in9Minutes ) ;
63
63
64
64
const cache1 = InstallationTokenCache . getInstance ( ) ;
65
65
const cache2 = InstallationTokenCache . getInstance ( ) ;
@@ -77,8 +77,8 @@ describe("InstallationTokenCache", () => {
77
77
const GITHUB_APP_ID_1 = 31 ;
78
78
const GITHUB_APP_ID_2 = 32 ;
79
79
jest . setSystemTime ( now ) ;
80
- const token1 = new AuthToken ( "token1" , in10Minutes ) ;
81
- const token2 = new AuthToken ( "token2" , in10Minutes ) ;
80
+ const token1 = new AuthToken ( "token1" , in9Minutes ) ;
81
+ const token2 = new AuthToken ( "token2" , in9Minutes ) ;
82
82
83
83
const cache1 = InstallationTokenCache . getInstance ( ) ;
84
84
const cache2 = InstallationTokenCache . getInstance ( ) ;
@@ -95,8 +95,8 @@ describe("InstallationTokenCache", () => {
95
95
const CONFLICTIN_GITHUB_INSTALLATION_ID = 41 ;
96
96
const GITHUB_APP_ID = 41 ;
97
97
jest . setSystemTime ( now ) ;
98
- const token1 = new AuthToken ( "token1" , in10Minutes ) ;
99
- const token2 = new AuthToken ( "token2" , in10Minutes ) ;
98
+ const token1 = new AuthToken ( "token1" , in9Minutes ) ;
99
+ const token2 = new AuthToken ( "token2" , in9Minutes ) ;
100
100
101
101
const cache1 = InstallationTokenCache . getInstance ( ) ;
102
102
const cache2 = InstallationTokenCache . getInstance ( ) ;
@@ -109,10 +109,10 @@ describe("InstallationTokenCache", () => {
109
109
} ) ;
110
110
111
111
it ( "Re-generates expired tokens" , async ( ) => {
112
- const initialInstallationToken = new AuthToken ( "initial installation token" , in10Minutes ) ;
112
+ const initialInstallationToken = new AuthToken ( "initial installation token" , in9Minutes ) ;
113
113
const generateInitialInstallationToken = jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( initialInstallationToken ) ) ;
114
114
115
- const freshInstallationToken = new AuthToken ( "fresh installation token" , in20Minutes ) ;
115
+ const freshInstallationToken = new AuthToken ( "fresh installation token" , in18Minutes ) ;
116
116
const generateFreshInstallationToken = jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( freshInstallationToken ) ) ;
117
117
118
118
const githubInstallationId = 123456 ;
@@ -132,7 +132,7 @@ describe("InstallationTokenCache", () => {
132
132
expect ( generateFreshInstallationToken ) . toHaveBeenCalledTimes ( 0 ) ;
133
133
134
134
// after 10 minutes we expect a new token because the old one has expired
135
- jest . setSystemTime ( in10Minutes ) ;
135
+ jest . setSystemTime ( in9Minutes ) ;
136
136
const token3 = await installationTokenCache . getInstallationToken ( githubInstallationId , undefined , generateFreshInstallationToken ) ;
137
137
expect ( token3 ) . toEqual ( freshInstallationToken ) ;
138
138
expect ( generateInitialInstallationToken ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments