@@ -22,6 +22,9 @@ import {describe, it, beforeEach} from 'mocha';
2222import { Probot , ProbotOctokit } from 'probot' ;
2323// eslint-disable-next-line node/no-extraneous-import
2424import { Octokit } from '@octokit/rest' ;
25+ import { getAuthenticatedOctokit } from 'gcf-utils' ;
26+ import * as gcfUtilsModule from 'gcf-utils' ;
27+ import * as sinon from 'sinon' ;
2528
2629import {
2730 getConfig ,
@@ -64,7 +67,7 @@ const app = (app: Probot) => {
6467 CONFIG_FILENAME
6568 ) ;
6669 await configChecker . validateConfigChanges (
67- context . octokit ,
70+ await getAuthenticatedOctokit ( context . payload . installation ! . id ) ,
6871 context . payload . pull_request . head . user . login ,
6972 context . payload . repository . name ,
7073 context . payload . pull_request . head . sha ,
@@ -90,7 +93,7 @@ const app2 = (app: Probot) => {
9093 CONFIG_FILENAME_YML
9194 ) ;
9295 await configChecker . validateConfigChanges (
93- context . octokit ,
96+ await getAuthenticatedOctokit ( context . payload . installation ! . id ) ,
9497 context . payload . pull_request . head . user . login ,
9598 context . payload . repository . name ,
9699 context . payload . pull_request . head . sha ,
@@ -116,7 +119,7 @@ const app3 = (app: Probot) => {
116119 [ schema ]
117120 ) ;
118121 await configChecker . validateConfigChanges (
119- context . octokit ,
122+ await getAuthenticatedOctokit ( context . payload . installation ! . id ) ,
120123 context . payload . pull_request . head . user . login ,
121124 context . payload . repository . name ,
122125 context . payload . pull_request . head . sha ,
@@ -173,8 +176,11 @@ function fetchFilesInPR(configFile: string, fileName: string) {
173176 . reply ( 200 , createConfigResponse ( configFile ) ) ;
174177}
175178
179+ let getAuthenticatedOctokitStub : sinon . SinonStub ;
180+
176181describe ( 'config test app with config.yml' , ( ) => {
177182 let probot : Probot ;
183+ const sandbox = sinon . createSandbox ( ) ;
178184 beforeEach ( ( ) => {
179185 probot = new Probot ( {
180186 githubToken : 'abc123' ,
@@ -184,12 +190,16 @@ describe('config test app with config.yml', () => {
184190 } ) ,
185191 } ) ;
186192 probot . load ( app2 ) ;
187- } ) ;
188- beforeEach ( ( ) => {
189193 nock . disableNetConnect ( ) ;
194+ getAuthenticatedOctokitStub = sandbox . stub (
195+ gcfUtilsModule ,
196+ 'getAuthenticatedOctokit'
197+ ) ;
198+ getAuthenticatedOctokitStub . resolves ( new Octokit ( ) ) ;
190199 } ) ;
191200 afterEach ( ( ) => {
192201 nock . cleanAll ( ) ;
202+ sandbox . restore ( ) ;
193203 } ) ;
194204 describe ( 'responds to PR' , ( ) => {
195205 it ( 'creates a failing status check for a wrong file name' , async ( ) => {
@@ -211,6 +221,7 @@ describe('config test app with config.yml', () => {
211221
212222describe ( 'config test app' , ( ) => {
213223 let probot : Probot ;
224+ const sandbox = sinon . createSandbox ( ) ;
214225 beforeEach ( ( ) => {
215226 probot = new Probot ( {
216227 githubToken : 'abc123' ,
@@ -223,9 +234,15 @@ describe('config test app', () => {
223234 // It always start from null.
224235 configFromConfigChecker = null ;
225236 nock . disableNetConnect ( ) ;
237+ getAuthenticatedOctokitStub = sandbox . stub (
238+ gcfUtilsModule ,
239+ 'getAuthenticatedOctokit'
240+ ) ;
241+ getAuthenticatedOctokitStub . resolves ( new Octokit ( ) ) ;
226242 } ) ;
227243 afterEach ( ( ) => {
228244 nock . cleanAll ( ) ;
245+ sandbox . restore ( ) ;
229246 } ) ;
230247 describe ( 'responds to PR' , ( ) => {
231248 it ( 'does not die upon 404 github api responses' , async ( ) => {
@@ -311,6 +328,7 @@ describe('config test app', () => {
311328
312329describe ( 'config test app with multiple schema files' , ( ) => {
313330 let probot : Probot ;
331+ const sandbox = sinon . createSandbox ( ) ;
314332 beforeEach ( ( ) => {
315333 probot = new Probot ( {
316334 githubToken : 'abc123' ,
@@ -323,9 +341,15 @@ describe('config test app with multiple schema files', () => {
323341 // It always start from null.
324342 listConfigFromConfigChecker = null ;
325343 nock . disableNetConnect ( ) ;
344+ getAuthenticatedOctokitStub = sandbox . stub (
345+ gcfUtilsModule ,
346+ 'getAuthenticatedOctokit'
347+ ) ;
348+ getAuthenticatedOctokitStub . resolves ( new Octokit ( ) ) ;
326349 } ) ;
327350 afterEach ( ( ) => {
328351 nock . cleanAll ( ) ;
352+ sandbox . restore ( ) ;
329353 } ) ;
330354 describe ( 'responds to PR' , ( ) => {
331355 it ( 'does not creates a failing status check for a correct config' , async ( ) => {
0 commit comments