|
5 | 5 | mockPersonalAccessTokenAccount,
|
6 | 6 | } from '../__mocks__/state-mocks';
|
7 | 7 |
|
| 8 | +import log from 'electron-log'; |
8 | 9 | import { defaultSettings } from '../context/App';
|
9 | 10 | import type { Hostname, Link, SettingsState } from '../types';
|
10 | 11 | import type { SubjectType } from '../typesGitHub';
|
@@ -505,23 +506,57 @@ describe('utils/helpers.ts', () => {
|
505 | 506 | });
|
506 | 507 | });
|
507 | 508 |
|
508 |
| - it('defaults to repository url', async () => { |
509 |
| - const subject = { |
510 |
| - title: 'generate github web url unit tests', |
511 |
| - url: null, |
512 |
| - latest_comment_url: null, |
513 |
| - type: 'Issue' as SubjectType, |
514 |
| - }; |
| 509 | + describe('defaults to repository url', () => { |
| 510 | + it('defaults when no urls present in notification', async () => { |
| 511 | + const subject = { |
| 512 | + title: 'generate github web url unit tests', |
| 513 | + url: null, |
| 514 | + latest_comment_url: null, |
| 515 | + type: 'Issue' as SubjectType, |
| 516 | + }; |
515 | 517 |
|
516 |
| - const result = await generateGitHubWebUrl({ |
517 |
| - ...mockSingleNotification, |
518 |
| - subject: subject, |
| 518 | + const result = await generateGitHubWebUrl({ |
| 519 | + ...mockSingleNotification, |
| 520 | + subject: subject, |
| 521 | + }); |
| 522 | + |
| 523 | + expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); |
| 524 | + expect(result).toBe( |
| 525 | + `${mockSingleNotification.repository.html_url}?${mockNotificationReferrer}`, |
| 526 | + ); |
519 | 527 | });
|
520 | 528 |
|
521 |
| - expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); |
522 |
| - expect(result).toBe( |
523 |
| - `${mockSingleNotification.repository.html_url}?${mockNotificationReferrer}`, |
524 |
| - ); |
| 529 | + it('defaults when exception handled during specialized html enrichment process', async () => { |
| 530 | + const logErrorSpy = jest.spyOn(log, 'error').mockImplementation(); |
| 531 | + |
| 532 | + const subject = { |
| 533 | + title: 'generate github web url unit tests', |
| 534 | + url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/1' as Link, |
| 535 | + latest_comment_url: |
| 536 | + 'https://api.github.com/repos/gitify-app/notifications-test/issues/comments/302888448' as Link, |
| 537 | + type: 'Issue' as SubjectType, |
| 538 | + }; |
| 539 | + |
| 540 | + const mockError = new Error('Test error'); |
| 541 | + |
| 542 | + apiRequestAuthMock.mockRejectedValue(mockError); |
| 543 | + |
| 544 | + const result = await generateGitHubWebUrl({ |
| 545 | + ...mockSingleNotification, |
| 546 | + subject: subject, |
| 547 | + }); |
| 548 | + |
| 549 | + expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); |
| 550 | + expect(apiRequestAuthMock).toHaveBeenCalledWith( |
| 551 | + subject.latest_comment_url, |
| 552 | + 'GET', |
| 553 | + mockPersonalAccessTokenAccount.token, |
| 554 | + ); |
| 555 | + expect(result).toBe( |
| 556 | + `https://github.com/gitify-app/notifications-test?${mockNotificationReferrer}`, |
| 557 | + ); |
| 558 | + expect(logErrorSpy).toHaveBeenCalledTimes(2); |
| 559 | + }); |
525 | 560 | });
|
526 | 561 | });
|
527 | 562 |
|
|
0 commit comments