@@ -104,95 +104,4 @@ describe('run-remote-query', function() {
104104 } ) ;
105105
106106 } ) ;
107-
108- describe ( 'attemptRerun' , ( ) => {
109- let sandbox : sinon . SinonSandbox ;
110- let showAndLogErrorMessageSpy : sinon . SinonStub ;
111- let showInformationMessageWithActionSpy : sinon . SinonStub ;
112- let mockRequest : sinon . SinonStub ;
113- let logSpy : sinon . SinonStub ;
114- let mod : any ;
115-
116- const error = {
117- message : 'Unable to run query on the specified repositories. Some repositories were invalid.' ,
118- response : {
119- data : {
120- invalid_repos : [ 'abc/def' , 'ghi/jkl' ]
121- }
122- }
123- } ;
124- const ref = 'main' ;
125- const language = 'javascript' ;
126- const credentials = getMockCredentials ( 0 ) ;
127- const query = 'select 1' ;
128- const owner = 'owner' ;
129- const repo = 'repo' ;
130-
131- beforeEach ( ( ) => {
132- sandbox = sinon . createSandbox ( ) ;
133- logSpy = sandbox . stub ( ) ;
134- showAndLogErrorMessageSpy = sandbox . stub ( ) ;
135- showInformationMessageWithActionSpy = sandbox . stub ( ) ;
136- mod = proxyquire ( '../../remote-queries/run-remote-query' , {
137- '../helpers' : {
138- showAndLogErrorMessage : showAndLogErrorMessageSpy ,
139- showInformationMessageWithAction : showInformationMessageWithActionSpy
140- } ,
141- '../logging' : {
142- 'logger' : {
143- log : logSpy
144- }
145- } ,
146- } ) ;
147- } ) ;
148- afterEach ( ( ) => {
149- sandbox . restore ( ) ;
150- } ) ;
151-
152- it ( 'should return and log error if it can\'t run on any repos' , async ( ) => {
153- const repositories = [ 'abc/def' , 'ghi/jkl' ] ;
154-
155- // make the function call
156- await mod . attemptRerun ( error , credentials , ref , language , repositories , query , owner , repo ) ;
157-
158- // check logging output
159- expect ( logSpy . firstCall . args [ 0 ] ) . to . contain ( 'Unable to run query' ) ;
160- expect ( logSpy . secondCall . args [ 0 ] ) . to . contain ( 'Invalid repos: abc/def, ghi/jkl' ) ;
161- expect ( showAndLogErrorMessageSpy . firstCall . args [ 0 ] ) . to . contain ( 'Unable to run query on any' ) ;
162- } ) ;
163-
164- it ( 'should list invalid repos and rerun on valid ones' , async ( ) => {
165- const repositories = [ 'foo/bar' , 'abc/def' , 'ghi/jkl' , 'foo/baz' ] ;
166-
167- // fake return values
168- showInformationMessageWithActionSpy . resolves ( true ) ;
169-
170- // make the function call
171- await mod . attemptRerun ( error , credentials , ref , language , repositories , query , owner , repo ) ;
172-
173- // check logging output
174- expect ( logSpy . firstCall . args [ 0 ] ) . to . contain ( 'Unable to run query' ) ;
175- expect ( logSpy . secondCall . args [ 0 ] ) . to . contain ( 'Invalid repos: abc/def, ghi/jkl' ) ;
176-
177- // check that the correct information message is displayed
178- expect ( showInformationMessageWithActionSpy . firstCall . args [ 0 ] ) . to . contain ( 'Unable to run query on some' ) ;
179- expect ( showInformationMessageWithActionSpy . firstCall . args [ 1 ] ) . to . contain ( 'Rerun' ) ;
180-
181- // check that API request is made again, with only valid repos
182- expect ( logSpy . lastCall . args [ 0 ] ) . to . contain ( 'valid repositories: ["foo/bar","foo/baz"]' ) ;
183- // test a few values in the octokit request
184- expect ( mockRequest . firstCall . args [ 1 ] . data . language ) . to . eq ( 'javascript' ) ;
185- expect ( mockRequest . firstCall . args [ 1 ] . data . repositories ) . to . deep . eq ( [ 'foo/bar' , 'foo/baz' ] ) ;
186-
187- } ) ;
188-
189- function getMockCredentials ( response : any ) {
190- mockRequest = sinon . stub ( ) . resolves ( response ) ;
191- return {
192- getOctokit : ( ) => ( {
193- request : mockRequest
194- } )
195- } ;
196- }
197- } ) ;
198107} ) ;
0 commit comments