Skip to content

feat: support repository invitation links #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/utils/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('utils/helpers.ts', () => {
describe('generateGitHubWebUrl', () => {
const mockedHtmlUrl = 'https://github.com/gitify-app/gitify/issues/785';
const mockedNotificationReferrer =
'?notification_referrer_id=MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk%3D';
'notification_referrer_id=MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk%3D';
const apiRequestAuthMock = jest.spyOn(apiRequests, 'apiRequestAuth');

afterEach(() => {
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('utils/helpers.ts', () => {
'GET',
mockAccounts.token,
);
expect(result).toBe(`${mockedHtmlUrl}${mockedNotificationReferrer}`);
expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`);
});

it('Subject Url: when no latest comment url available, fetch subject html url', async () => {
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('utils/helpers.ts', () => {
'GET',
mockAccounts.token,
);
expect(result).toBe(`${mockedHtmlUrl}${mockedNotificationReferrer}`);
expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`);
});

it('Discussions: when no subject urls and no discussions found via query, default to linking to repository discussions', async () => {
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('utils/helpers.ts', () => {

expect(apiRequestAuthMock).toHaveBeenCalledTimes(1);
expect(result).toBe(
`${mockedSingleNotification.repository.html_url}/discussions${mockedNotificationReferrer}`,
`${mockedSingleNotification.repository.html_url}/discussions?${mockedNotificationReferrer}`,
);
});

Expand All @@ -268,8 +268,6 @@ describe('utils/helpers.ts', () => {
type: 'Discussion' as SubjectType,
};

// const latestDiscussionCommentId = 12345;

const requestPromise = new Promise((resolve) =>
resolve(mockedGraphQLResponse as AxiosResponse),
) as AxiosPromise;
Expand All @@ -286,7 +284,29 @@ describe('utils/helpers.ts', () => {

expect(apiRequestAuthMock).toHaveBeenCalledTimes(1);
expect(result).toBe(
'https://github.com/manosim/notifications-test/discussions/612?notification_referrer_id=MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk%3D#discussioncomment-2300902',
`https://github.com/manosim/notifications-test/discussions/612?${mockedNotificationReferrer}#discussioncomment-2300902`,
);
});

it('Repository Invitation url', async () => {
const subject = {
title: 'Invitation to join manosim/notifications-test from unit-tests',
url: null,
latest_comment_url: null,
type: 'RepositoryInvitation' as SubjectType,
};

const result = await generateGitHubWebUrl(
{
...mockedSingleNotification,
subject: subject,
},
mockAccounts,
);

expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
expect(result).toBe(
`https://github.com/manosim/notifications-test/invitations?${mockedNotificationReferrer}`,
);
});

Expand All @@ -308,7 +328,7 @@ describe('utils/helpers.ts', () => {

expect(apiRequestAuthMock).toHaveBeenCalledTimes(0);
expect(result).toBe(
`${mockedSingleNotification.repository.html_url}${mockedNotificationReferrer}`,
`${mockedSingleNotification.repository.html_url}?${mockedNotificationReferrer}`,
);
});
});
Expand Down
3 changes: 3 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export async function generateGitHubWebUrl(
case 'Discussion':
url = await getDiscussionUrl(notification, accounts.token);
break;
case 'RepositoryInvitation':
url = `${notification.repository.html_url}/invitations`;
break;
default:
url = notification.repository.html_url;
break;
Expand Down