Skip to content

Commit 6729fa9

Browse files
committed
feat(url): improve fallback url handling
Signed-off-by: Adam Setch <[email protected]>
1 parent c273335 commit 6729fa9

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

src/renderer/utils/helpers.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
generateGitHubWebUrl,
1717
generateNotificationReferrerId,
1818
getChevronDetails,
19+
getDefaultURLForType,
1920
getPlatformFromHostname,
2021
isEnterpriseServerHost,
2122
} from './helpers';
@@ -416,7 +417,7 @@ describe('renderer/utils/helpers.ts', () => {
416417
);
417418
});
418419

419-
it('issues - defaults when no urls present in notification', async () => {
420+
it('pull requests - defaults when no urls present in notification', async () => {
420421
const subject = {
421422
title: 'generate github web url unit tests',
422423
url: null,
@@ -482,6 +483,38 @@ describe('renderer/utils/helpers.ts', () => {
482483
});
483484
});
484485

486+
describe('getDefaultURLForType', () => {
487+
let mockUrl: URL;
488+
489+
beforeEach(() => {
490+
mockUrl = new URL('https://github.com/gitify-app/notifications-test');
491+
});
492+
493+
it('discussions', () => {
494+
expect(getDefaultURLForType(mockUrl, 'Discussion')).toEqual(
495+
'https://github.com/gitify-app/notifications-test/discussions',
496+
);
497+
});
498+
499+
it('issues', () => {
500+
expect(getDefaultURLForType(mockUrl, 'Issue')).toEqual(
501+
'https://github.com/gitify-app/notifications-test/issues',
502+
);
503+
});
504+
505+
it('pull requests', () => {
506+
expect(getDefaultURLForType(mockUrl, 'PullRequest')).toEqual(
507+
'https://github.com/gitify-app/notifications-test/pulls',
508+
);
509+
});
510+
511+
it('default', () => {
512+
expect(getDefaultURLForType(mockUrl, 'RepositoryInvitation')).toEqual(
513+
'https://github.com/gitify-app/notifications-test',
514+
);
515+
});
516+
});
517+
485518
describe('getChevronDetails', () => {
486519
it('should return correct chevron details', () => {
487520
expect(getChevronDetails(true, true, 'account')).toEqual({

src/renderer/utils/helpers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export async function generateGitHubWebUrl(
136136
notification.account.token,
137137
);
138138
} else {
139-
url.href = defaultGitHubWebUrl(url, notification.subject.type);
139+
url.href = getDefaultURLForType(url, notification.subject.type);
140140
}
141141
}
142142
} catch (err) {
@@ -147,7 +147,7 @@ export async function generateGitHubWebUrl(
147147
notification,
148148
);
149149

150-
url.href = defaultGitHubWebUrl(url, notification.subject.type);
150+
url.href = getDefaultURLForType(url, notification.subject.type);
151151
}
152152

153153
url.searchParams.set(
@@ -158,14 +158,14 @@ export async function generateGitHubWebUrl(
158158
return url.toString() as Link;
159159
}
160160

161-
export function defaultGitHubWebUrl(url: URL, type: SubjectType) {
161+
export function getDefaultURLForType(url: URL, type: SubjectType) {
162162
switch (type) {
163-
case 'Issue':
164-
url.pathname += '/issues';
165-
break;
166163
case 'Discussion':
167164
url.pathname += '/discussions';
168165
break;
166+
case 'Issue':
167+
url.pathname += '/issues';
168+
break;
169169
case 'PullRequest':
170170
url.pathname += '/pulls';
171171
break;

0 commit comments

Comments
 (0)