@@ -22,6 +22,7 @@ import {
2222import { createMockVariantAnalysis } from "../../../factories/variant-analysis/shared/variant-analysis" ;
2323import { createMockApp } from "../../../__mocks__/appMock" ;
2424import { createMockCommandManager } from "../../../__mocks__/commandsMock" ;
25+ import * as helpers from "../../../../src/helpers" ;
2526
2627jest . setTimeout ( 60_000 ) ;
2728
@@ -196,6 +197,93 @@ describe("Variant Analysis Monitor", () => {
196197 } ) ;
197198 } ) ;
198199
200+ describe ( "when some responses fail" , ( ) => {
201+ let showAndLogWarningMessageSpy : jest . SpiedFunction <
202+ typeof helpers . showAndLogWarningMessage
203+ > ;
204+
205+ let scannedRepos : ApiVariantAnalysisScannedRepository [ ] ;
206+
207+ beforeEach ( async ( ) => {
208+ showAndLogWarningMessageSpy = jest
209+ . spyOn ( helpers , "showAndLogWarningMessage" )
210+ . mockResolvedValue ( undefined ) ;
211+
212+ scannedRepos = createMockScannedRepos ( [
213+ "pending" ,
214+ "in_progress" ,
215+ "in_progress" ,
216+ "in_progress" ,
217+ "pending" ,
218+ "pending" ,
219+ ] ) ;
220+ mockApiResponse = createMockApiResponse ( "in_progress" , scannedRepos ) ;
221+ mockGetVariantAnalysis . mockResolvedValueOnce ( mockApiResponse ) ;
222+
223+ mockGetVariantAnalysis . mockRejectedValueOnce (
224+ new Error ( "No internet connection" ) ,
225+ ) ;
226+ mockGetVariantAnalysis . mockRejectedValueOnce (
227+ new Error ( "No internet connection" ) ,
228+ ) ;
229+ mockGetVariantAnalysis . mockRejectedValueOnce (
230+ new Error ( "My different error" ) ,
231+ ) ;
232+
233+ let nextApiResponse = {
234+ ...mockApiResponse ,
235+ scanned_repositories : [ ...scannedRepos . map ( ( r ) => ( { ...r } ) ) ] ,
236+ } ;
237+ nextApiResponse . scanned_repositories [ 0 ] . analysis_status = "succeeded" ;
238+ nextApiResponse . scanned_repositories [ 1 ] . analysis_status = "succeeded" ;
239+
240+ mockGetVariantAnalysis . mockResolvedValueOnce ( nextApiResponse ) ;
241+
242+ mockGetVariantAnalysis . mockRejectedValueOnce (
243+ new Error ( "My different error" ) ,
244+ ) ;
245+ mockGetVariantAnalysis . mockRejectedValueOnce (
246+ new Error ( "My different error" ) ,
247+ ) ;
248+ mockGetVariantAnalysis . mockRejectedValueOnce (
249+ new Error ( "Another different error" ) ,
250+ ) ;
251+
252+ nextApiResponse = {
253+ ...mockApiResponse ,
254+ scanned_repositories : [ ...scannedRepos . map ( ( r ) => ( { ...r } ) ) ] ,
255+ } ;
256+ nextApiResponse . scanned_repositories [ 2 ] . analysis_status = "succeeded" ;
257+ nextApiResponse . scanned_repositories [ 3 ] . analysis_status = "succeeded" ;
258+ nextApiResponse . scanned_repositories [ 4 ] . analysis_status = "failed" ;
259+ nextApiResponse . scanned_repositories [ 5 ] . analysis_status = "succeeded" ;
260+ nextApiResponse . status = "succeeded" ;
261+ mockGetVariantAnalysis . mockResolvedValueOnce ( nextApiResponse ) ;
262+ } ) ;
263+
264+ it ( "should only trigger the warning once per error" , async ( ) => {
265+ await variantAnalysisMonitor . monitorVariantAnalysis ( variantAnalysis ) ;
266+
267+ expect ( showAndLogWarningMessageSpy ) . toBeCalledTimes ( 4 ) ;
268+ expect ( showAndLogWarningMessageSpy ) . toHaveBeenNthCalledWith (
269+ 1 ,
270+ expect . stringMatching ( / N o i n t e r n e t c o n n e c t i o n / ) ,
271+ ) ;
272+ expect ( showAndLogWarningMessageSpy ) . toHaveBeenNthCalledWith (
273+ 2 ,
274+ expect . stringMatching ( / M y d i f f e r e n t e r r o r / ) ,
275+ ) ;
276+ expect ( showAndLogWarningMessageSpy ) . toHaveBeenNthCalledWith (
277+ 3 ,
278+ expect . stringMatching ( / M y d i f f e r e n t e r r o r / ) ,
279+ ) ;
280+ expect ( showAndLogWarningMessageSpy ) . toHaveBeenNthCalledWith (
281+ 4 ,
282+ expect . stringMatching ( / A n o t h e r d i f f e r e n t e r r o r / ) ,
283+ ) ;
284+ } ) ;
285+ } ) ;
286+
199287 describe ( "when there are no repos to scan" , ( ) => {
200288 beforeEach ( async ( ) => {
201289 scannedRepos = [ ] ;
0 commit comments