Skip to content

Commit fec2a79

Browse files
committed
feat(api): codegen for discussions
Signed-off-by: Adam Setch <[email protected]>
1 parent 027a3e9 commit fec2a79

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

src/renderer/utils/helpers.test.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ describe('renderer/utils/helpers.ts', () => {
281281
'fetchDiscussionByNumber',
282282
);
283283

284-
it('when no subject urls and no discussions found via query, default to linking to repository discussions', async () => {
284+
it('when no discussion found via graphql api, default to base repository discussion url', async () => {
285285
const subject = {
286286
title: 'generate github web url unit tests',
287287
url: null,
@@ -304,7 +304,40 @@ describe('renderer/utils/helpers.ts', () => {
304304
);
305305
});
306306

307-
it('link to matching discussion and comment hash', async () => {
307+
it('when error fetching discussion via graphql api, default to base repository discussion url', async () => {
308+
const rendererLogErrorSpy = jest
309+
.spyOn(logger, 'rendererLogError')
310+
.mockImplementation();
311+
312+
const subject = {
313+
title: '1.16.0',
314+
url: null,
315+
latest_comment_url: null,
316+
type: 'Discussion' as SubjectType,
317+
};
318+
319+
fetchDiscussionByNumberSpy.mockResolvedValue({
320+
data: null,
321+
errors: [
322+
{
323+
message: 'Something failed',
324+
},
325+
],
326+
} as GitHubGraphQLResponse<FetchDiscussionByNumberQuery>);
327+
328+
const result = await generateGitHubWebUrl({
329+
...mockSingleNotification,
330+
subject: subject,
331+
});
332+
333+
expect(fetchDiscussionByNumberSpy).toHaveBeenCalledTimes(1);
334+
expect(result).toBe(
335+
`https://github.com/gitify-app/notifications-test/discussions?${mockNotificationReferrer}`,
336+
);
337+
expect(rendererLogErrorSpy).toHaveBeenCalledTimes(1);
338+
});
339+
340+
it('when discussion found via graphql api, link to matching discussion and comment hash', async () => {
308341
const subject = {
309342
title: '1.16.0',
310343
url: null,
@@ -327,7 +360,7 @@ describe('renderer/utils/helpers.ts', () => {
327360
);
328361
});
329362

330-
it('default to base discussions url when graphql query fails', async () => {
363+
it('when api throws error, default to base repository discussion url', async () => {
331364
const rendererLogErrorSpy = jest
332365
.spyOn(logger, 'rendererLogError')
333366
.mockImplementation();
@@ -339,13 +372,9 @@ describe('renderer/utils/helpers.ts', () => {
339372
type: 'Discussion' as SubjectType,
340373
};
341374

342-
fetchDiscussionByNumberSpy.mockResolvedValue({
343-
errors: [
344-
{
345-
message: 'Something failed',
346-
},
347-
],
348-
} as GitHubGraphQLResponse<FetchDiscussionByNumberQuery>);
375+
fetchDiscussionByNumberSpy.mockRejectedValue(
376+
new Error('Something failed'),
377+
);
349378

350379
const result = await generateGitHubWebUrl({
351380
...mockSingleNotification,

0 commit comments

Comments
 (0)