@@ -273,7 +273,7 @@ describe('renderer/utils/helpers.ts', () => {
273273 } ) ;
274274
275275 describe ( 'Discussions URLs' , ( ) => {
276- it ( 'when no subject urls and no discussions found via query , default to linking to repository discussions ' , async ( ) => {
276+ it ( 'when no discussion found via graphql api , default to base repository discussion url ' , async ( ) => {
277277 const subject = {
278278 title : 'generate github web url unit tests' ,
279279 url : null ,
@@ -296,7 +296,11 @@ describe('renderer/utils/helpers.ts', () => {
296296 ) ;
297297 } ) ;
298298
299- it ( 'link to matching discussion and comment hash' , async ( ) => {
299+ it ( 'when error fetching discussion via graphql api, default to base repository discussion url' , async ( ) => {
300+ const rendererLogErrorSpy = jest
301+ . spyOn ( logger , 'rendererLogError' )
302+ . mockImplementation ( ) ;
303+
300304 const subject = {
301305 title : '1.16.0' ,
302306 url : null ,
@@ -306,7 +310,12 @@ describe('renderer/utils/helpers.ts', () => {
306310
307311 apiRequestAuthSpy . mockResolvedValue ( {
308312 data : {
309- ...mockGraphQLResponse ,
313+ data : null ,
314+ errors : [
315+ {
316+ message : 'Something failed' ,
317+ } ,
318+ ] ,
310319 } ,
311320 } as AxiosResponse ) ;
312321
@@ -317,23 +326,24 @@ describe('renderer/utils/helpers.ts', () => {
317326
318327 expect ( apiRequestAuthSpy ) . toHaveBeenCalledTimes ( 1 ) ;
319328 expect ( result ) . toBe (
320- `https://github.com/gitify-app/notifications-test/discussions/612 ?${ mockNotificationReferrer } #discussioncomment-2300902 ` ,
329+ `https://github.com/gitify-app/notifications-test/discussions?${ mockNotificationReferrer } ` ,
321330 ) ;
331+ expect ( rendererLogErrorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
322332 } ) ;
323333
324- it ( 'default to base discussions url when graphql query fails' , async ( ) => {
325- const rendererLogErrorSpy = jest
326- . spyOn ( logger , 'rendererLogError' )
327- . mockImplementation ( ) ;
328-
334+ it ( 'when discussion found via graphql api, link to matching discussion and comment hash' , async ( ) => {
329335 const subject = {
330336 title : '1.16.0' ,
331337 url : null ,
332338 latest_comment_url : null ,
333339 type : 'Discussion' as SubjectType ,
334340 } ;
335341
336- apiRequestAuthSpy . mockResolvedValue ( null as AxiosResponse ) ;
342+ apiRequestAuthSpy . mockResolvedValue ( {
343+ data : {
344+ ...mockGraphQLResponse ,
345+ } ,
346+ } as AxiosResponse ) ;
337347
338348 const result = await generateGitHubWebUrl ( {
339349 ...mockSingleNotification ,
@@ -342,9 +352,8 @@ describe('renderer/utils/helpers.ts', () => {
342352
343353 expect ( apiRequestAuthSpy ) . toHaveBeenCalledTimes ( 1 ) ;
344354 expect ( result ) . toBe (
345- `https://github.com/gitify-app/notifications-test/discussions?${ mockNotificationReferrer } ` ,
355+ `https://github.com/gitify-app/notifications-test/discussions/612 ?${ mockNotificationReferrer } #discussioncomment-2300902 ` ,
346356 ) ;
347- expect ( rendererLogErrorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
348357 } ) ;
349358 } ) ;
350359
@@ -447,8 +456,8 @@ describe('renderer/utils/helpers.ts', () => {
447456 } ) ;
448457 } ) ;
449458
450- describe ( 'defaults to repository url ' , ( ) => {
451- it ( 'defaults when no urls present in notification' , async ( ) => {
459+ describe ( 'defaults web urls ' , ( ) => {
460+ it ( 'issues - defaults when no urls present in notification' , async ( ) => {
452461 const subject = {
453462 title : 'generate github web url unit tests' ,
454463 url : null ,
@@ -463,7 +472,45 @@ describe('renderer/utils/helpers.ts', () => {
463472
464473 expect ( apiRequestAuthSpy ) . toHaveBeenCalledTimes ( 0 ) ;
465474 expect ( result ) . toBe (
466- `${ mockSingleNotification . repository . html_url } ?${ mockNotificationReferrer } ` ,
475+ `https://github.com/gitify-app/notifications-test/issues?${ mockNotificationReferrer } ` ,
476+ ) ;
477+ } ) ;
478+
479+ it ( 'issues - defaults when no urls present in notification' , async ( ) => {
480+ const subject = {
481+ title : 'generate github web url unit tests' ,
482+ url : null ,
483+ latest_comment_url : null ,
484+ type : 'PullRequest' as SubjectType ,
485+ } ;
486+
487+ const result = await generateGitHubWebUrl ( {
488+ ...mockSingleNotification ,
489+ subject : subject ,
490+ } ) ;
491+
492+ expect ( apiRequestAuthSpy ) . toHaveBeenCalledTimes ( 0 ) ;
493+ expect ( result ) . toBe (
494+ `https://github.com/gitify-app/notifications-test/pulls?${ mockNotificationReferrer } ` ,
495+ ) ;
496+ } ) ;
497+
498+ it ( 'other - defaults when no urls present in notification' , async ( ) => {
499+ const subject = {
500+ title : 'generate github web url unit tests' ,
501+ url : null ,
502+ latest_comment_url : null ,
503+ type : 'Commit' as SubjectType ,
504+ } ;
505+
506+ const result = await generateGitHubWebUrl ( {
507+ ...mockSingleNotification ,
508+ subject : subject ,
509+ } ) ;
510+
511+ expect ( apiRequestAuthSpy ) . toHaveBeenCalledTimes ( 0 ) ;
512+ expect ( result ) . toBe (
513+ `https://github.com/gitify-app/notifications-test?${ mockNotificationReferrer } ` ,
467514 ) ;
468515 } ) ;
469516
@@ -474,31 +521,23 @@ describe('renderer/utils/helpers.ts', () => {
474521
475522 const subject = {
476523 title : 'generate github web url unit tests' ,
477- url : 'https://api.github.com/repos/gitify-app/notifications-test/issues/1' as Link ,
478- latest_comment_url :
479- 'https://api.github.com/repos/gitify-app/notifications-test/issues/comments/302888448' as Link ,
480- type : 'Issue' as SubjectType ,
524+ url : 'https://api.github.com/repos/gitify-app/notifications-test/discussion/1' as Link ,
525+ latest_comment_url : null as Link ,
526+ type : 'Discussion' as SubjectType ,
481527 } ;
482528
483- const mockError = new Error ( 'Test error' ) ;
484-
485- apiRequestAuthSpy . mockRejectedValue ( mockError ) ;
529+ apiRequestAuthSpy . mockRejectedValue ( new Error ( 'Test error' ) ) ;
486530
487531 const result = await generateGitHubWebUrl ( {
488532 ...mockSingleNotification ,
489533 subject : subject ,
490534 } ) ;
491535
492536 expect ( apiRequestAuthSpy ) . toHaveBeenCalledTimes ( 1 ) ;
493- expect ( apiRequestAuthSpy ) . toHaveBeenCalledWith (
494- subject . latest_comment_url ,
495- 'GET' ,
496- mockPersonalAccessTokenAccount . token ,
497- ) ;
498537 expect ( result ) . toBe (
499- `https://github.com/gitify-app/notifications-test?${ mockNotificationReferrer } ` ,
538+ `https://github.com/gitify-app/notifications-test/discussions ?${ mockNotificationReferrer } ` ,
500539 ) ;
501- expect ( rendererLogErrorSpy ) . toHaveBeenCalledTimes ( 2 ) ;
540+ expect ( rendererLogErrorSpy ) . toHaveBeenCalledTimes ( 1 ) ;
502541 } ) ;
503542 } ) ;
504543 } ) ;
0 commit comments