@@ -26,7 +26,8 @@ jest.mock('./runners');
26
26
jest . mock ( './gh-auth' ) ;
27
27
28
28
const mocktokit = Octokit as jest . MockedClass < typeof Octokit > ;
29
- const mockedAuth = mocked ( ghAuth . createGithubAuth , true ) ;
29
+ const mockedAppAuth = mocked ( ghAuth . createGithubAppAuth , true ) ;
30
+ const mockedInstallationAuth = mocked ( ghAuth . createGithubInstallationAuth , true ) ;
30
31
const mockCreateClient = mocked ( ghAuth . createOctoClient , true ) ;
31
32
32
33
const TEST_DATA : scaleUpModule . ActionRequestMessage = {
@@ -115,12 +116,21 @@ beforeEach(() => {
115
116
116
117
describe ( 'scaleUp with GHES' , ( ) => {
117
118
beforeEach ( ( ) => {
118
- mockedAuth . mockResolvedValue ( {
119
+ mockedAppAuth . mockResolvedValue ( {
119
120
type : 'app' ,
120
121
token : 'token' ,
121
122
appId : TEST_DATA . installationId ,
122
123
expiresAt : 'some-date' ,
123
124
} ) ;
125
+ mockedInstallationAuth . mockResolvedValue ( {
126
+ type : 'token' ,
127
+ tokenType : 'installation' ,
128
+ token : 'token' ,
129
+ createdAt : 'some-date' ,
130
+ expiresAt : 'some-date' ,
131
+ permissions : { } ,
132
+ repositorySelection : 'all' ,
133
+ } ) ;
124
134
125
135
mockCreateClient . mockResolvedValue ( new mocktokit ( ) ) ;
126
136
@@ -180,26 +190,23 @@ describe('scaleUp with GHES', () => {
180
190
} ) ;
181
191
182
192
it ( 'does not retrieve installation id if already set' , async ( ) => {
183
- const spy = jest . spyOn ( ghAuth , 'createGithubAuth' ) ;
193
+ const appSpy = jest . spyOn ( ghAuth , 'createGithubAppAuth' ) ;
194
+ const installationSpy = jest . spyOn ( ghAuth , 'createGithubInstallationAuth' ) ;
184
195
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA ) ;
185
196
expect ( mockOctokit . apps . getOrgInstallation ) . not . toBeCalled ( ) ;
186
197
expect ( mockOctokit . apps . getRepoInstallation ) . not . toBeCalled ( ) ;
187
- expect ( spy ) . toBeCalledWith (
188
- TEST_DATA . installationId ,
189
- 'installation' ,
190
- 'https://github.enterprise.something/api/v3' ,
191
- ) ;
198
+ expect ( appSpy ) . not . toBeCalled ( ) ;
199
+ expect ( installationSpy ) . toBeCalledWith ( TEST_DATA . installationId , 'https://github.enterprise.something/api/v3' ) ;
192
200
} ) ;
193
201
194
202
it ( 'retrieves installation id if not set' , async ( ) => {
195
- const spy = jest . spyOn ( ghAuth , 'createGithubAuth' ) ;
203
+ const appSpy = jest . spyOn ( ghAuth , 'createGithubAppAuth' ) ;
204
+ const installationSpy = jest . spyOn ( ghAuth , 'createGithubInstallationAuth' ) ;
196
205
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA_WITH_ZERO_INSTALL_ID ) ;
197
206
expect ( mockOctokit . apps . getRepoInstallation ) . not . toBeCalled ( ) ;
198
- expect ( spy ) . toHaveBeenNthCalledWith ( 1 , undefined , 'app' , 'https://github.enterprise.something/api/v3' ) ;
199
- expect ( spy ) . toHaveBeenNthCalledWith (
200
- 2 ,
207
+ expect ( appSpy ) . toHaveBeenCalledWith ( undefined , 'https://github.enterprise.something/api/v3' ) ;
208
+ expect ( installationSpy ) . toHaveBeenCalledWith (
201
209
TEST_DATA . installationId ,
202
- 'installation' ,
203
210
'https://github.enterprise.something/api/v3' ,
204
211
) ;
205
212
} ) ;
@@ -271,7 +278,7 @@ describe('scaleUp with GHES', () => {
271
278
expect ( mockOctokit . actions . createRegistrationTokenForOrg ) . not . toBeCalled ( ) ;
272
279
expect ( mockOctokit . actions . createRegistrationTokenForRepo ) . not . toBeCalled ( ) ;
273
280
} ) ;
274
-
281
+
275
282
it ( 'creates a token when maximum runners has not been reached' , async ( ) => {
276
283
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA ) ;
277
284
expect ( mockOctokit . actions . createRegistrationTokenForOrg ) . not . toBeCalled ( ) ;
@@ -291,30 +298,27 @@ describe('scaleUp with GHES', () => {
291
298
} ) ;
292
299
293
300
it ( 'does not retrieve installation id if already set' , async ( ) => {
294
- const spy = jest . spyOn ( ghAuth , 'createGithubAuth' ) ;
301
+ const appSpy = jest . spyOn ( ghAuth , 'createGithubAppAuth' ) ;
302
+ const installationSpy = jest . spyOn ( ghAuth , 'createGithubInstallationAuth' ) ;
295
303
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA ) ;
296
304
expect ( mockOctokit . apps . getOrgInstallation ) . not . toBeCalled ( ) ;
297
305
expect ( mockOctokit . apps . getRepoInstallation ) . not . toBeCalled ( ) ;
298
- expect ( spy ) . toBeCalledWith (
299
- TEST_DATA . installationId ,
300
- 'installation' ,
301
- 'https://github.enterprise.something/api/v3' ,
302
- ) ;
306
+ expect ( appSpy ) . not . toBeCalled ( ) ;
307
+ expect ( installationSpy ) . toBeCalledWith ( TEST_DATA . installationId , 'https://github.enterprise.something/api/v3' ) ;
303
308
} ) ;
304
309
305
310
it ( 'retrieves installation id if not set' , async ( ) => {
306
- const spy = jest . spyOn ( ghAuth , 'createGithubAuth' ) ;
311
+ const appSpy = jest . spyOn ( ghAuth , 'createGithubAppAuth' ) ;
312
+ const installationSpy = jest . spyOn ( ghAuth , 'createGithubInstallationAuth' ) ;
307
313
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA_WITH_ZERO_INSTALL_ID ) ;
308
314
expect ( mockOctokit . apps . getOrgInstallation ) . not . toBeCalled ( ) ;
309
315
expect ( mockOctokit . apps . getRepoInstallation ) . toBeCalledWith ( {
310
316
owner : TEST_DATA . repositoryOwner ,
311
317
repo : TEST_DATA . repositoryName ,
312
318
} ) ;
313
- expect ( spy ) . toHaveBeenNthCalledWith ( 1 , undefined , 'app' , 'https://github.enterprise.something/api/v3' ) ;
314
- expect ( spy ) . toHaveBeenNthCalledWith (
315
- 2 ,
319
+ expect ( appSpy ) . toHaveBeenCalledWith ( undefined , 'https://github.enterprise.something/api/v3' ) ;
320
+ expect ( installationSpy ) . toHaveBeenCalledWith (
316
321
TEST_DATA . installationId ,
317
- 'installation' ,
318
322
'https://github.enterprise.something/api/v3' ,
319
323
) ;
320
324
} ) ;
@@ -371,20 +375,23 @@ describe('scaleUp with public GH', () => {
371
375
} ) ;
372
376
373
377
it ( 'does not retrieve installation id if already set' , async ( ) => {
374
- const spy = jest . spyOn ( ghAuth , 'createGithubAuth' ) ;
378
+ const appSpy = jest . spyOn ( ghAuth , 'createGithubAppAuth' ) ;
379
+ const installationSpy = jest . spyOn ( ghAuth , 'createGithubInstallationAuth' ) ;
375
380
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA ) ;
376
381
expect ( mockOctokit . apps . getOrgInstallation ) . not . toBeCalled ( ) ;
377
382
expect ( mockOctokit . apps . getRepoInstallation ) . not . toBeCalled ( ) ;
378
- expect ( spy ) . toBeCalledWith ( TEST_DATA . installationId , 'installation' , '' ) ;
383
+ expect ( appSpy ) . not . toBeCalled ( ) ;
384
+ expect ( installationSpy ) . toBeCalledWith ( TEST_DATA . installationId , '' ) ;
379
385
} ) ;
380
386
381
387
it ( 'retrieves installation id if not set' , async ( ) => {
382
- const spy = jest . spyOn ( ghAuth , 'createGithubAuth' ) ;
388
+ const appSpy = jest . spyOn ( ghAuth , 'createGithubAppAuth' ) ;
389
+ const installationSpy = jest . spyOn ( ghAuth , 'createGithubInstallationAuth' ) ;
383
390
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA_WITH_ZERO_INSTALL_ID ) ;
384
391
expect ( mockOctokit . apps . getOrgInstallation ) . toBeCalled ( ) ;
385
392
expect ( mockOctokit . apps . getRepoInstallation ) . not . toBeCalled ( ) ;
386
- expect ( spy ) . toHaveBeenNthCalledWith ( 1 , undefined , 'app' , '' ) ;
387
- expect ( spy ) . toHaveBeenNthCalledWith ( 2 , TEST_DATA . installationId , 'installation' , '' ) ;
393
+ expect ( appSpy ) . toHaveBeenCalledWith ( undefined , '' ) ;
394
+ expect ( installationSpy ) . toHaveBeenCalledWith ( TEST_DATA . installationId , '' ) ;
388
395
} ) ;
389
396
390
397
it ( 'does not list runners when no workflows are queued' , async ( ) => {
@@ -481,7 +488,7 @@ describe('scaleUp with public GH', () => {
481
488
expect ( mockOctokit . actions . createRegistrationTokenForOrg ) . not . toBeCalled ( ) ;
482
489
expect ( mockOctokit . actions . createRegistrationTokenForRepo ) . not . toBeCalled ( ) ;
483
490
} ) ;
484
-
491
+
485
492
it ( 'creates a token when maximum runners has not been reached' , async ( ) => {
486
493
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA ) ;
487
494
expect ( mockOctokit . actions . createRegistrationTokenForOrg ) . not . toBeCalled ( ) ;
@@ -492,20 +499,23 @@ describe('scaleUp with public GH', () => {
492
499
} ) ;
493
500
494
501
it ( 'does not retrieve installation id if already set' , async ( ) => {
495
- const spy = jest . spyOn ( ghAuth , 'createGithubAuth' ) ;
502
+ const appSpy = jest . spyOn ( ghAuth , 'createGithubAppAuth' ) ;
503
+ const installationSpy = jest . spyOn ( ghAuth , 'createGithubInstallationAuth' ) ;
496
504
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA ) ;
497
505
expect ( mockOctokit . apps . getOrgInstallation ) . not . toBeCalled ( ) ;
498
506
expect ( mockOctokit . apps . getRepoInstallation ) . not . toBeCalled ( ) ;
499
- expect ( spy ) . toBeCalledWith ( TEST_DATA . installationId , 'installation' , '' ) ;
507
+ expect ( appSpy ) . not . toBeCalled ( ) ;
508
+ expect ( installationSpy ) . toBeCalledWith ( TEST_DATA . installationId , '' ) ;
500
509
} ) ;
501
510
502
511
it ( 'retrieves installation id if not set' , async ( ) => {
503
- const spy = jest . spyOn ( ghAuth , 'createGithubAuth' ) ;
512
+ const appSpy = jest . spyOn ( ghAuth , 'createGithubAppAuth' ) ;
513
+ const installationSpy = jest . spyOn ( ghAuth , 'createGithubInstallationAuth' ) ;
504
514
await scaleUpModule . scaleUp ( 'aws:sqs' , TEST_DATA_WITH_ZERO_INSTALL_ID ) ;
505
515
expect ( mockOctokit . apps . getOrgInstallation ) . not . toBeCalled ( ) ;
506
516
expect ( mockOctokit . apps . getRepoInstallation ) . toBeCalled ( ) ;
507
- expect ( spy ) . toHaveBeenNthCalledWith ( 1 , undefined , 'app' , '' ) ;
508
- expect ( spy ) . toHaveBeenNthCalledWith ( 2 , TEST_DATA . installationId , 'installation' , '' ) ;
517
+ expect ( appSpy ) . toHaveBeenCalledWith ( undefined , '' ) ;
518
+ expect ( installationSpy ) . toHaveBeenCalledWith ( TEST_DATA . installationId , '' ) ;
509
519
} ) ;
510
520
511
521
it ( 'creates a runner with correct config and labels' , async ( ) => {
0 commit comments