From fb397bd6543721dbf200dd1a79116daba46938f0 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 26 Feb 2024 09:17:32 -0500 Subject: [PATCH 1/9] feat: support discussion states --- src/__mocks__/mockedData.ts | 2 + src/hooks/useNotifications.ts | 70 +++++++++++++++++++++-------------- src/typesGithub.ts | 15 +++++++- src/utils/github-api.ts | 16 +++++++- src/utils/helpers.ts | 45 ++++++++++++++++++++++ 5 files changed, 117 insertions(+), 31 deletions(-) diff --git a/src/__mocks__/mockedData.ts b/src/__mocks__/mockedData.ts index 228ae1558..269aaf363 100644 --- a/src/__mocks__/mockedData.ts +++ b/src/__mocks__/mockedData.ts @@ -286,6 +286,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { viewerSubscription: 'SUBSCRIBED', title: '1.16.0', url: 'https://github.com/manosim/notifications-test/discussions/612', + stateReason: null, comments: { edges: [ { @@ -388,6 +389,7 @@ export const mockedGraphQLResponse: GraphQLSearch = { viewerSubscription: 'IGNORED', title: '1.16.0', url: 'https://github.com/manosim/notifications-test/discussions/612', + stateReason: 'RESOLVED', comments: { edges: [ { diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts index 7ad405149..4d875a44a 100644 --- a/src/hooks/useNotifications.ts +++ b/src/hooks/useNotifications.ts @@ -9,6 +9,7 @@ import { getEnterpriseAccountToken, generateGitHubAPIUrl, isEnterpriseHost, + getDiscussionState, } from '../utils/helpers'; import { removeNotification } from '../utils/remove-notification'; import { @@ -130,12 +131,6 @@ export const useNotifications = (colors: boolean): NotificationsState => { notifications: await axios.all( accountNotifications.notifications.map( async (notification: Notification) => { - if ( - notification.subject.type !== 'PullRequest' && - notification.subject.type !== 'Issue' - ) { - return notification; - } const isEnterprise = isEnterpriseHost( accountNotifications.hostname, ); @@ -146,28 +141,47 @@ export const useNotifications = (colors: boolean): NotificationsState => { ) : accounts.token; - const cardinalData = ( - await apiRequestAuth( - notification.subject.url, - 'GET', - token, - ) - ).data; - - const state = - cardinalData.state === 'closed' - ? cardinalData.state_reason || - (cardinalData.merged && 'merged') || - 'closed' - : (cardinalData.draft && 'draft') || 'open'; - - return { - ...notification, - subject: { - ...notification.subject, - state, - }, - }; + switch (notification.subject.type) { + case 'Discussion': + const discussionState = await getDiscussionState( + notification, + token, + ); + + return { + ...notification, + subject: { + ...notification.subject, + state: discussionState, + }, + }; + case 'Issue': + case 'PullRequest': + const cardinalData = ( + await apiRequestAuth( + notification.subject.url, + 'GET', + token, + ) + ).data; + + const state = + cardinalData.state === 'closed' + ? cardinalData.state_reason || + (cardinalData.merged && 'merged') || + 'closed' + : (cardinalData.draft && 'draft') || 'open'; + + return { + ...notification, + subject: { + ...notification.subject, + state, + }, + }; + default: + return notification; + } }, ), ), diff --git a/src/typesGithub.ts b/src/typesGithub.ts index 04803c4d1..53648e25b 100644 --- a/src/typesGithub.ts +++ b/src/typesGithub.ts @@ -15,6 +15,13 @@ export type Reason = | 'subscribed' | 'team_mention'; +export type DiscussionStateType = + | 'DUPLICATE' + | 'REOPENED' + | 'RESOLVED' + | 'OPEN' + | 'OUTDATED'; + export type SubjectType = | 'CheckSuite' | 'Commit' @@ -35,7 +42,10 @@ export type IssueStateType = export type PullRequestStateType = 'closed' | 'open' | 'merged' | 'draft'; -export type StateType = IssueStateType | PullRequestStateType; +export type StateType = + | DiscussionStateType + | IssueStateType + | PullRequestStateType; export type ViewerSubscription = 'IGNORED' | 'SUBSCRIBED' | 'UNSUBSCRIBED'; @@ -145,7 +155,7 @@ export interface Owner { export interface Subject { title: string; url: string | null; - state?: StateType; + state?: StateType; // This is not in the GitHub API, but we add it to the type to make it easier to work with latest_comment_url: string | null; type: SubjectType; } @@ -165,6 +175,7 @@ export interface DiscussionEdge { viewerSubscription: ViewerSubscription; title: string; url: string; + stateReason: DiscussionStateType; comments: { edges: DiscussionCommentEdge[]; }; diff --git a/src/utils/github-api.ts b/src/utils/github-api.ts index 2fa8d09f9..35d47b345 100644 --- a/src/utils/github-api.ts +++ b/src/utils/github-api.ts @@ -2,6 +2,9 @@ import { AlertIcon, CheckIcon, CommentDiscussionIcon, + DiscussionClosedIcon, + DiscussionDuplicateIcon, + DiscussionOutdatedIcon, GitCommitIcon, GitMergeIcon, GitPullRequestClosedIcon, @@ -106,7 +109,16 @@ export function getNotificationTypeIcon( case 'Commit': return GitCommitIcon; case 'Discussion': - return CommentDiscussionIcon; + switch (subject.state) { + case 'DUPLICATE': + return DiscussionDuplicateIcon; + case 'OUTDATED': + return DiscussionOutdatedIcon; + case 'RESOLVED': + return DiscussionClosedIcon; + default: + return CommentDiscussionIcon; + } case 'Issue': switch (subject.state) { case 'draft': @@ -165,6 +177,8 @@ export function getNotificationTypeIconColor(subject: Subject): string { case 'closed': return 'text-red-500'; case 'completed': + case 'merged': + case 'RESOLVED': return 'text-purple-500'; case 'draft': return 'text-gray-600'; diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 48cd13476..a157ca8dc 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -3,6 +3,7 @@ import { Notification, GraphQLSearch, DiscussionCommentEdge, + DiscussionStateType, } from '../typesGithub'; import { apiRequestAuth } from '../utils/api-requests'; import { openExternalLink } from '../utils/comms'; @@ -92,6 +93,7 @@ async function getDiscussionUrl( viewerSubscription title url + stateReason comments(last: 100) { edges { node { @@ -139,6 +141,49 @@ async function getDiscussionUrl( return url; } +export async function getDiscussionState( + notification: Notification, + token: string, +): Promise { + const response: GraphQLSearch = await apiRequestAuth( + `https://api.github.com/graphql`, + 'POST', + token, + { + query: `{ + search(query:"${formatSearchQueryString( + notification.repository.full_name, + notification.subject.title, + notification.updated_at, + )}", type: DISCUSSION, first: 10) { + edges { + node { + ... on Discussion { + viewerSubscription + title + url + stateReason + } + } + } + } + }`, + }, + ); + let edges = + response?.data?.data?.search?.edges?.filter( + (edge) => edge.node.title === notification.subject.title, + ) || []; + if (edges.length > 1) + edges = edges.filter( + (edge) => edge.node.viewerSubscription === 'SUBSCRIBED', + ); + + if (edges[0]) { + return edges[0].node.stateReason ?? 'OPEN'; + } +} + export const getLatestDiscussionCommentId = ( comments: DiscussionCommentEdge[], ) => From c6414a3316fd43313d134614bd24e76b5d79a69a Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 26 Feb 2024 09:37:35 -0500 Subject: [PATCH 2/9] feat: support discussion states --- src/typesGithub.ts | 1 + src/utils/github-api.test.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/typesGithub.ts b/src/typesGithub.ts index 53648e25b..7c0eba6c1 100644 --- a/src/typesGithub.ts +++ b/src/typesGithub.ts @@ -15,6 +15,7 @@ export type Reason = | 'subscribed' | 'team_mention'; +// Note: OPEN is not an official discussion state type in the GitHub API export type DiscussionStateType = | 'DUPLICATE' | 'REOPENED' diff --git a/src/utils/github-api.test.ts b/src/utils/github-api.test.ts index 019f3c4e2..c90b46a10 100644 --- a/src/utils/github-api.test.ts +++ b/src/utils/github-api.test.ts @@ -72,6 +72,21 @@ describe('getNotificationTypeIcon', () => { getNotificationTypeIcon(createSubjectMock({ type: 'Discussion' })) .displayName, ).toBe('CommentDiscussionIcon'); + expect( + getNotificationTypeIcon( + createSubjectMock({ type: 'Discussion', state: 'DUPLICATE' }), + ).displayName, + ).toBe('DiscussionDuplicateIcon'); + expect( + getNotificationTypeIcon( + createSubjectMock({ type: 'Discussion', state: 'OUTDATED' }), + ).displayName, + ).toBe('DiscussionOutdatedIcon'); + expect( + getNotificationTypeIcon( + createSubjectMock({ type: 'Discussion', state: 'RESOLVED' }), + ).displayName, + ).toBe('DiscussionClosedIcon'); expect( getNotificationTypeIcon(createSubjectMock({ type: 'Issue' })).displayName, ).toBe('IssueOpenedIcon'); From a704180fa4260d8f9f0566f79385892d8577104b Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 26 Feb 2024 10:17:10 -0500 Subject: [PATCH 3/9] feat: add test coverage --- src/hooks/useNotifications.test.ts | 214 +++++++++++++++++++++++++++-- src/typesGithub.ts | 6 +- 2 files changed, 207 insertions(+), 13 deletions(-) diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index 2d133363f..b66e1d470 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -191,28 +191,43 @@ describe('hooks/useNotifications.ts', () => { const notifications = [ { id: 1, - title: 'This is a notification.', - subject: { type: 'Issue', url: 'https://api.github.com/1' }, + subject: { + title: 'This is a notification.', + type: 'Issue', + url: 'https://api.github.com/1', + }, }, { id: 2, - title: 'A merged PR.', - subject: { type: 'PullRequest', url: 'https://api.github.com/2' }, + subject: { + title: 'A merged PR.', + type: 'PullRequest', + url: 'https://api.github.com/2', + }, }, { id: 3, - title: 'A closed PR.', - subject: { type: 'PullRequest', url: 'https://api.github.com/3' }, + subject: { + title: 'A closed PR.', + type: 'PullRequest', + url: 'https://api.github.com/3', + }, }, { id: 4, - title: 'A draft PR.', - subject: { type: 'PullRequest', url: 'https://api.github.com/4' }, + subject: { + title: 'A draft PR.', + type: 'PullRequest', + url: 'https://api.github.com/4', + }, }, { id: 5, - title: 'A draft PR.', - subject: { type: 'PullRequest', url: 'https://api.github.com/5' }, + subject: { + title: 'A draft PR.', + type: 'PullRequest', + url: 'https://api.github.com/5', + }, }, ]; @@ -266,6 +281,185 @@ describe('hooks/useNotifications.ts', () => { result.current.notifications[0].notifications[4].subject.state, ).toBe('draft'); }); + + it('should fetch discussion notifications with success - with colors', async () => { + const accounts: AuthState = { + ...mockAccounts, + enterpriseAccounts: [], + user: mockedUser, + }; + + const notifications = [ + { + id: 1, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a duplicate discussion', + type: 'Discussion', + }, + }, + { + id: 2, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is an open discussion', + type: 'Discussion', + }, + }, + { + id: 3, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is nm outdated discussion', + type: 'Discussion', + }, + }, + { + id: 4, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a reopened discussion', + type: 'Discussion', + }, + }, + { + id: 5, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a resolved discussion', + type: 'Discussion', + }, + }, + ]; + + nock('https://api.github.com') + .get('/notifications?participating=false') + .reply(200, notifications); + + nock('https://api.github.com') + .post('/graphql') + .reply(200, { + data: { + search: { + edges: [ + { + node: { + title: 'This is a duplicate discussion', + stateReason: 'DUPLICATE', + }, + }, + ], + }, + }, + }) + .post('/graphql') + .reply(200, { + data: { + search: { + edges: [ + { + node: { + title: 'This is an open discussion', + stateReason: null, + }, + }, + ], + }, + }, + }) + .post('/graphql') + .reply(200, { + data: { + search: { + edges: [ + { + node: { + title: 'This is nm outdated discussion', + stateReason: 'OUTDATED', + }, + }, + ], + }, + }, + }) + .post('/graphql') + .reply(200, { + data: { + search: { + edges: [ + { + node: { + title: 'This is a reopened discussion', + stateReason: 'REOPENED', + }, + }, + ], + }, + }, + }) + .post('/graphql') + .reply(200, { + data: { + search: { + edges: [ + { + node: { + title: 'This is a resolved discussion', + stateReason: 'RESOLVED', + }, + }, + ], + }, + }, + }); + + const { result } = renderHook(() => useNotifications(true)); + + act(() => { + result.current.fetchNotifications(accounts, { + ...mockSettings, + colors: true, + }); + }); + + expect(result.current.isFetching).toBe(true); + + await waitFor(() => { + expect(result.current.notifications[0].hostname).toBe('github.com'); + }); + + expect(result.current.notifications[0].notifications.length).toBe(5); + expect( + result.current.notifications[0].notifications[0].subject.state, + ).toBe('DUPLICATE'); + expect( + result.current.notifications[0].notifications[1].subject.state, + ).toBe('OPEN'); + expect( + result.current.notifications[0].notifications[2].subject.state, + ).toBe('OUTDATED'); + expect( + result.current.notifications[0].notifications[3].subject.state, + ).toBe('REOPENED'); + expect( + result.current.notifications[0].notifications[4].subject.state, + ).toBe('RESOLVED'); + }); }); }); diff --git a/src/typesGithub.ts b/src/typesGithub.ts index 7c0eba6c1..752c80ed4 100644 --- a/src/typesGithub.ts +++ b/src/typesGithub.ts @@ -18,10 +18,10 @@ export type Reason = // Note: OPEN is not an official discussion state type in the GitHub API export type DiscussionStateType = | 'DUPLICATE' - | 'REOPENED' - | 'RESOLVED' | 'OPEN' - | 'OUTDATED'; + | 'OUTDATED' + | 'REOPENED' + | 'RESOLVED'; export type SubjectType = | 'CheckSuite' From c0e4705f099f7cbbd9b7c2226405c8ea6a28fb84 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 26 Feb 2024 10:29:38 -0500 Subject: [PATCH 4/9] feat: add test coverage --- src/hooks/useNotifications.test.ts | 38 +++++++++++++++++++++++++++++- src/utils/helpers.ts | 2 ++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index b66e1d470..15476823b 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -345,6 +345,17 @@ describe('hooks/useNotifications.ts', () => { type: 'Discussion', }, }, + { + id: 6, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a default discussion', + type: 'Discussion', + }, + }, ]; nock('https://api.github.com') @@ -376,6 +387,14 @@ describe('hooks/useNotifications.ts', () => { node: { title: 'This is an open discussion', stateReason: null, + viewerSubscription: 'SUBSCRIBED', + }, + }, + { + node: { + title: 'This is an open discussion', + stateReason: null, + viewerSubscription: 'IGNORED', }, }, ], @@ -426,6 +445,20 @@ describe('hooks/useNotifications.ts', () => { ], }, }, + }) + .post('/graphql') + .reply(200, { + data: { + search: { + edges: [ + { + node: { + title: 'unknown search result', + }, + }, + ], + }, + }, }); const { result } = renderHook(() => useNotifications(true)); @@ -443,7 +476,7 @@ describe('hooks/useNotifications.ts', () => { expect(result.current.notifications[0].hostname).toBe('github.com'); }); - expect(result.current.notifications[0].notifications.length).toBe(5); + expect(result.current.notifications[0].notifications.length).toBe(6); expect( result.current.notifications[0].notifications[0].subject.state, ).toBe('DUPLICATE'); @@ -459,6 +492,9 @@ describe('hooks/useNotifications.ts', () => { expect( result.current.notifications[0].notifications[4].subject.state, ).toBe('RESOLVED'); + expect( + result.current.notifications[0].notifications[5].subject.state, + ).toBe('OPEN'); }); }); }); diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index a157ca8dc..d19c1b894 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -182,6 +182,8 @@ export async function getDiscussionState( if (edges[0]) { return edges[0].node.stateReason ?? 'OPEN'; } + + return 'OPEN'; } export const getLatestDiscussionCommentId = ( From ffec197780bbbd609ad68e628c71fae67081bbea Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 26 Feb 2024 10:34:54 -0500 Subject: [PATCH 5/9] feat: add test coverage --- src/utils/__snapshots__/github-api.test.ts.snap | 4 +++- src/utils/github-api.test.ts | 3 +++ src/utils/github-api.ts | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/utils/__snapshots__/github-api.test.ts.snap b/src/utils/__snapshots__/github-api.test.ts.snap index e6b226300..adab84317 100644 --- a/src/utils/__snapshots__/github-api.test.ts.snap +++ b/src/utils/__snapshots__/github-api.test.ts.snap @@ -136,4 +136,6 @@ exports[`getNotificationTypeIconColor should format the notification color for s exports[`getNotificationTypeIconColor should format the notification color for state 7`] = `"text-green-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 8`] = `"text-gray-300"`; +exports[`getNotificationTypeIconColor should format the notification color for state 8`] = `"text-purple-500"`; + +exports[`getNotificationTypeIconColor should format the notification color for state 9`] = `"text-gray-300"`; diff --git a/src/utils/github-api.test.ts b/src/utils/github-api.test.ts index c90b46a10..d0f167102 100644 --- a/src/utils/github-api.test.ts +++ b/src/utils/github-api.test.ts @@ -248,6 +248,9 @@ describe('getNotificationTypeIconColor', () => { expect( getNotificationTypeIconColor(createSubjectMock({ state: 'reopened' })), ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'RESOLVED' })), + ).toMatchSnapshot(); expect( getNotificationTypeIconColor( createSubjectMock({ diff --git a/src/utils/github-api.ts b/src/utils/github-api.ts index 35d47b345..fb6c8372d 100644 --- a/src/utils/github-api.ts +++ b/src/utils/github-api.ts @@ -177,8 +177,6 @@ export function getNotificationTypeIconColor(subject: Subject): string { case 'closed': return 'text-red-500'; case 'completed': - case 'merged': - case 'RESOLVED': return 'text-purple-500'; case 'draft': return 'text-gray-600'; @@ -190,6 +188,8 @@ export function getNotificationTypeIconColor(subject: Subject): string { return 'text-green-500'; case 'reopened': return 'text-green-500'; + case 'RESOLVED': + return 'text-purple-500'; default: return 'text-gray-300'; } From 1beb3dc85ba04ab8191ada53a851e2d32e65a96a Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 27 Feb 2024 06:57:23 -0500 Subject: [PATCH 6/9] refactor graphql search interface to be generic. add support for answered discussion --- src/__mocks__/mockedData.ts | 353 +++++++++--------- src/typesGithub.ts | 19 +- .../__snapshots__/github-api.test.ts.snap | 18 +- src/utils/github-api.test.ts | 3 + src/utils/github-api.ts | 2 + src/utils/helpers.ts | 32 +- 6 files changed, 224 insertions(+), 203 deletions(-) diff --git a/src/__mocks__/mockedData.ts b/src/__mocks__/mockedData.ts index 269aaf363..cfa1ef9bc 100644 --- a/src/__mocks__/mockedData.ts +++ b/src/__mocks__/mockedData.ts @@ -1,5 +1,11 @@ import { AccountNotifications, EnterpriseAccount } from '../types'; -import { Notification, Repository, User, GraphQLSearch } from '../typesGithub'; +import { + Notification, + Repository, + User, + GraphQLSearch, + DiscussionSearchResultEdge, +} from '../typesGithub'; export const mockedEnterpriseAccounts: EnterpriseAccount[] = [ { @@ -276,219 +282,218 @@ export const mockedSingleAccountNotifications: AccountNotifications[] = [ }, ]; -export const mockedGraphQLResponse: GraphQLSearch = { - data: { +export const mockedGraphQLResponse: GraphQLSearch = + { data: { - search: { - edges: [ - { - node: { - viewerSubscription: 'SUBSCRIBED', - title: '1.16.0', - url: 'https://github.com/manosim/notifications-test/discussions/612', - stateReason: null, - comments: { - edges: [ - { - node: { - databaseId: 2215656, - createdAt: '2022-02-20T18:33:39Z', - replies: { - edges: [], + data: { + search: { + edges: [ + { + node: { + viewerSubscription: 'SUBSCRIBED', + title: '1.16.0', + url: 'https://github.com/manosim/notifications-test/discussions/612', + comments: { + edges: [ + { + node: { + databaseId: 2215656, + createdAt: '2022-02-20T18:33:39Z', + replies: { + edges: [], + }, }, }, - }, - { - node: { - databaseId: 2217789, - createdAt: '2022-02-21T03:30:42Z', - replies: { - edges: [], + { + node: { + databaseId: 2217789, + createdAt: '2022-02-21T03:30:42Z', + replies: { + edges: [], + }, }, }, - }, - { - node: { - databaseId: 2223243, - createdAt: '2022-02-21T18:26:27Z', - replies: { - edges: [ - { - node: { - databaseId: 2232922, - createdAt: '2022-02-23T00:57:58Z', + { + node: { + databaseId: 2223243, + createdAt: '2022-02-21T18:26:27Z', + replies: { + edges: [ + { + node: { + databaseId: 2232922, + createdAt: '2022-02-23T00:57:58Z', + }, }, - }, - ], + ], + }, }, }, - }, - { - node: { - databaseId: 2232921, - createdAt: '2022-02-23T00:57:49Z', - replies: { - edges: [], + { + node: { + databaseId: 2232921, + createdAt: '2022-02-23T00:57:49Z', + replies: { + edges: [], + }, }, }, - }, - { - node: { - databaseId: 2258799, - createdAt: '2022-02-27T01:22:20Z', - replies: { - edges: [ - { - node: { - databaseId: 2300902, - createdAt: '2022-03-05T17:43:52Z', + { + node: { + databaseId: 2258799, + createdAt: '2022-02-27T01:22:20Z', + replies: { + edges: [ + { + node: { + databaseId: 2300902, + createdAt: '2022-03-05T17:43:52Z', + }, }, - }, - ], + ], + }, }, }, - }, - { - node: { - databaseId: 2297637, - createdAt: '2022-03-04T20:39:44Z', - replies: { - edges: [ - { - node: { - databaseId: 2300893, - createdAt: '2022-03-05T17:41:04Z', + { + node: { + databaseId: 2297637, + createdAt: '2022-03-04T20:39:44Z', + replies: { + edges: [ + { + node: { + databaseId: 2300893, + createdAt: '2022-03-05T17:41:04Z', + }, }, - }, - ], + ], + }, }, }, - }, - { - node: { - databaseId: 2299763, - createdAt: '2022-03-05T11:05:42Z', - replies: { - edges: [ - { - node: { - databaseId: 2300895, - createdAt: '2022-03-05T17:41:44Z', + { + node: { + databaseId: 2299763, + createdAt: '2022-03-05T11:05:42Z', + replies: { + edges: [ + { + node: { + databaseId: 2300895, + createdAt: '2022-03-05T17:41:44Z', + }, }, - }, - ], + ], + }, }, }, - }, - ], + ], + }, }, }, - }, - { - node: { - viewerSubscription: 'IGNORED', - title: '1.16.0', - url: 'https://github.com/manosim/notifications-test/discussions/612', - stateReason: 'RESOLVED', - comments: { - edges: [ - { - node: { - databaseId: 2215656, - createdAt: '2022-02-20T18:33:39Z', - replies: { - edges: [], + { + node: { + viewerSubscription: 'IGNORED', + title: '1.16.0', + url: 'https://github.com/manosim/notifications-test/discussions/612', + comments: { + edges: [ + { + node: { + databaseId: 2215656, + createdAt: '2022-02-20T18:33:39Z', + replies: { + edges: [], + }, }, }, - }, - { - node: { - databaseId: 2217789, - createdAt: '2022-02-21T03:30:42Z', - replies: { - edges: [], + { + node: { + databaseId: 2217789, + createdAt: '2022-02-21T03:30:42Z', + replies: { + edges: [], + }, }, }, - }, - { - node: { - databaseId: 2223243, - createdAt: '2022-02-21T18:26:27Z', - replies: { - edges: [ - { - node: { - databaseId: 2232922, - createdAt: '2022-02-23T00:57:58Z', + { + node: { + databaseId: 2223243, + createdAt: '2022-02-21T18:26:27Z', + replies: { + edges: [ + { + node: { + databaseId: 2232922, + createdAt: '2022-02-23T00:57:58Z', + }, }, - }, - ], + ], + }, }, }, - }, - { - node: { - databaseId: 2232921, - createdAt: '2022-02-23T00:57:49Z', - replies: { - edges: [], + { + node: { + databaseId: 2232921, + createdAt: '2022-02-23T00:57:49Z', + replies: { + edges: [], + }, }, }, - }, - { - node: { - databaseId: 2258799, - createdAt: '2022-02-27T01:22:20Z', - replies: { - edges: [ - { - node: { - databaseId: 2300902, - createdAt: '2022-03-05T17:43:52Z', + { + node: { + databaseId: 2258799, + createdAt: '2022-02-27T01:22:20Z', + replies: { + edges: [ + { + node: { + databaseId: 2300902, + createdAt: '2022-03-05T17:43:52Z', + }, }, - }, - ], + ], + }, }, }, - }, - { - node: { - databaseId: 2297637, - createdAt: '2022-03-04T20:39:44Z', - replies: { - edges: [ - { - node: { - databaseId: 2300893, - createdAt: '2022-03-05T17:41:04Z', + { + node: { + databaseId: 2297637, + createdAt: '2022-03-04T20:39:44Z', + replies: { + edges: [ + { + node: { + databaseId: 2300893, + createdAt: '2022-03-05T17:41:04Z', + }, }, - }, - ], + ], + }, }, }, - }, - { - node: { - databaseId: 2299763, - createdAt: '2022-03-05T11:05:42Z', - replies: { - edges: [ - { - node: { - databaseId: 2300895, - createdAt: '2022-03-05T17:41:44Z', + { + node: { + databaseId: 2299763, + createdAt: '2022-03-05T11:05:42Z', + replies: { + edges: [ + { + node: { + databaseId: 2300895, + createdAt: '2022-03-05T17:41:44Z', + }, }, - }, - ], + ], + }, }, }, - }, - ], + ], + }, }, }, - }, - ], + ], + }, }, }, - }, -}; + }; diff --git a/src/typesGithub.ts b/src/typesGithub.ts index 752c80ed4..669d54167 100644 --- a/src/typesGithub.ts +++ b/src/typesGithub.ts @@ -15,8 +15,9 @@ export type Reason = | 'subscribed' | 'team_mention'; -// Note: OPEN is not an official discussion state type in the GitHub API +// Note: ANSWERED and OPEN are not an official discussion state type in the GitHub API export type DiscussionStateType = + | 'ANSWERED' | 'DUPLICATE' | 'OPEN' | 'OUTDATED' @@ -161,22 +162,30 @@ export interface Subject { type: SubjectType; } -export interface GraphQLSearch { +export interface GraphQLSearch { data: { data: { search: { - edges: DiscussionEdge[]; + edges: T[]; }; }; }; } -export interface DiscussionEdge { +export interface DiscussionStateSearchResultEdge { node: { viewerSubscription: ViewerSubscription; title: string; - url: string; stateReason: DiscussionStateType; + isAnswered: boolean; + }; +} + +export interface DiscussionSearchResultEdge { + node: { + viewerSubscription: ViewerSubscription; + title: string; + url: string; comments: { edges: DiscussionCommentEdge[]; }; diff --git a/src/utils/__snapshots__/github-api.test.ts.snap b/src/utils/__snapshots__/github-api.test.ts.snap index adab84317..0b472531e 100644 --- a/src/utils/__snapshots__/github-api.test.ts.snap +++ b/src/utils/__snapshots__/github-api.test.ts.snap @@ -122,20 +122,22 @@ exports[`getNotificationTypeIconColor should format the notification color for c exports[`getNotificationTypeIconColor should format the notification color for check suite 5`] = `"text-gray-300"`; -exports[`getNotificationTypeIconColor should format the notification color for state 1`] = `"text-red-500"`; +exports[`getNotificationTypeIconColor should format the notification color for state 1`] = `"text-green-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 2`] = `"text-purple-500"`; +exports[`getNotificationTypeIconColor should format the notification color for state 2`] = `"text-red-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 3`] = `"text-gray-600"`; +exports[`getNotificationTypeIconColor should format the notification color for state 3`] = `"text-purple-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 4`] = `"text-purple-500"`; +exports[`getNotificationTypeIconColor should format the notification color for state 4`] = `"text-gray-600"`; -exports[`getNotificationTypeIconColor should format the notification color for state 5`] = `"text-gray-300"`; +exports[`getNotificationTypeIconColor should format the notification color for state 5`] = `"text-purple-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 6`] = `"text-green-500"`; +exports[`getNotificationTypeIconColor should format the notification color for state 6`] = `"text-gray-300"`; exports[`getNotificationTypeIconColor should format the notification color for state 7`] = `"text-green-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 8`] = `"text-purple-500"`; +exports[`getNotificationTypeIconColor should format the notification color for state 8`] = `"text-green-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 9`] = `"text-gray-300"`; +exports[`getNotificationTypeIconColor should format the notification color for state 9`] = `"text-purple-500"`; + +exports[`getNotificationTypeIconColor should format the notification color for state 10`] = `"text-gray-300"`; diff --git a/src/utils/github-api.test.ts b/src/utils/github-api.test.ts index d0f167102..67d8e23f1 100644 --- a/src/utils/github-api.test.ts +++ b/src/utils/github-api.test.ts @@ -227,6 +227,9 @@ describe('getNotificationTypeIconColor', () => { }); it('should format the notification color for state', () => { + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'ANSWERED' })), + ).toMatchSnapshot(); expect( getNotificationTypeIconColor(createSubjectMock({ state: 'closed' })), ).toMatchSnapshot(); diff --git a/src/utils/github-api.ts b/src/utils/github-api.ts index fb6c8372d..0ca97a01d 100644 --- a/src/utils/github-api.ts +++ b/src/utils/github-api.ts @@ -174,6 +174,8 @@ export function getNotificationTypeIconColor(subject: Subject): string { } switch (subject.state) { + case 'ANSWERED': + return 'text-green-500'; case 'closed': return 'text-red-500'; case 'completed': diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index d19c1b894..d343f7b13 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -4,6 +4,8 @@ import { GraphQLSearch, DiscussionCommentEdge, DiscussionStateType, + DiscussionStateSearchResultEdge, + DiscussionSearchResultEdge, } from '../typesGithub'; import { apiRequestAuth } from '../utils/api-requests'; import { openExternalLink } from '../utils/comms'; @@ -76,11 +78,8 @@ async function getDiscussionUrl( ): Promise { let url = `${notification.repository.html_url}/discussions`; - const response: GraphQLSearch = await apiRequestAuth( - `https://api.github.com/graphql`, - 'POST', - token, - { + const response: GraphQLSearch = + await apiRequestAuth(`https://api.github.com/graphql`, 'POST', token, { query: `{ search(query:"${formatSearchQueryString( notification.repository.full_name, @@ -115,8 +114,7 @@ async function getDiscussionUrl( } } }`, - }, - ); + }); let edges = response?.data?.data?.search?.edges?.filter( (edge) => edge.node.title === notification.subject.title, @@ -145,11 +143,8 @@ export async function getDiscussionState( notification: Notification, token: string, ): Promise { - const response: GraphQLSearch = await apiRequestAuth( - `https://api.github.com/graphql`, - 'POST', - token, - { + const response: GraphQLSearch = + await apiRequestAuth(`https://api.github.com/graphql`, 'POST', token, { query: `{ search(query:"${formatSearchQueryString( notification.repository.full_name, @@ -161,15 +156,14 @@ export async function getDiscussionState( ... on Discussion { viewerSubscription title - url stateReason + isAnswered } } } } }`, - }, - ); + }); let edges = response?.data?.data?.search?.edges?.filter( (edge) => edge.node.title === notification.subject.title, @@ -180,7 +174,13 @@ export async function getDiscussionState( ); if (edges[0]) { - return edges[0].node.stateReason ?? 'OPEN'; + if (edges[0].node.isAnswered) { + return 'ANSWERED'; + } + + if (edges[0].node.stateReason) { + return edges[0].node.stateReason; + } } return 'OPEN'; From b1d5b3a8e4da87d0f6487296c7fb04208834792f Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 27 Feb 2024 07:07:50 -0500 Subject: [PATCH 7/9] add tests for answered discussion --- src/hooks/useNotifications.test.ts | 94 +++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 26 deletions(-) diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index 15476823b..3f29e5af3 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -297,7 +297,7 @@ describe('hooks/useNotifications.ts', () => { full_name: 'some/repo', }, subject: { - title: 'This is a duplicate discussion', + title: 'This is an answered discussion', type: 'Discussion', }, }, @@ -308,7 +308,7 @@ describe('hooks/useNotifications.ts', () => { full_name: 'some/repo', }, subject: { - title: 'This is an open discussion', + title: 'This is a duplicate discussion', type: 'Discussion', }, }, @@ -319,7 +319,7 @@ describe('hooks/useNotifications.ts', () => { full_name: 'some/repo', }, subject: { - title: 'This is nm outdated discussion', + title: 'This is an open discussion', type: 'Discussion', }, }, @@ -330,7 +330,7 @@ describe('hooks/useNotifications.ts', () => { full_name: 'some/repo', }, subject: { - title: 'This is a reopened discussion', + title: 'This is nm outdated discussion', type: 'Discussion', }, }, @@ -341,7 +341,7 @@ describe('hooks/useNotifications.ts', () => { full_name: 'some/repo', }, subject: { - title: 'This is a resolved discussion', + title: 'This is a reopened discussion', type: 'Discussion', }, }, @@ -351,6 +351,17 @@ describe('hooks/useNotifications.ts', () => { repository: { full_name: 'some/repo', }, + subject: { + title: 'This is a resolved discussion', + type: 'Discussion', + }, + }, + { + id: 7, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, subject: { title: 'This is a default discussion', type: 'Discussion', @@ -363,6 +374,23 @@ describe('hooks/useNotifications.ts', () => { .reply(200, notifications); nock('https://api.github.com') + .post('/graphql') + .reply(200, { + data: { + search: { + edges: [ + { + node: { + title: 'This is an answered discussion', + viewerSubscription: 'SUBSCRIBED', + stateReason: null, + isAnswered: true, + }, + }, + ], + }, + }, + }) .post('/graphql') .reply(200, { data: { @@ -371,7 +399,9 @@ describe('hooks/useNotifications.ts', () => { { node: { title: 'This is a duplicate discussion', + viewerSubscription: 'SUBSCRIBED', stateReason: 'DUPLICATE', + isAnswered: false, }, }, ], @@ -386,15 +416,17 @@ describe('hooks/useNotifications.ts', () => { { node: { title: 'This is an open discussion', - stateReason: null, viewerSubscription: 'SUBSCRIBED', + stateReason: null, + isAnswered: false, }, }, { node: { title: 'This is an open discussion', - stateReason: null, viewerSubscription: 'IGNORED', + stateReason: null, + isAnswered: false, }, }, ], @@ -409,7 +441,9 @@ describe('hooks/useNotifications.ts', () => { { node: { title: 'This is nm outdated discussion', + viewerSubscription: 'SUBSCRIBED', stateReason: 'OUTDATED', + isAnswered: false, }, }, ], @@ -424,7 +458,9 @@ describe('hooks/useNotifications.ts', () => { { node: { title: 'This is a reopened discussion', + viewerSubscription: 'SUBSCRIBED', stateReason: 'REOPENED', + isAnswered: false, }, }, ], @@ -439,7 +475,9 @@ describe('hooks/useNotifications.ts', () => { { node: { title: 'This is a resolved discussion', + viewerSubscription: 'SUBSCRIBED', stateReason: 'RESOLVED', + isAnswered: false, }, }, ], @@ -454,6 +492,9 @@ describe('hooks/useNotifications.ts', () => { { node: { title: 'unknown search result', + viewerSubscription: 'SUBSCRIBED', + stateReason: null, + isAnswered: false, }, }, ], @@ -476,25 +517,26 @@ describe('hooks/useNotifications.ts', () => { expect(result.current.notifications[0].hostname).toBe('github.com'); }); - expect(result.current.notifications[0].notifications.length).toBe(6); - expect( - result.current.notifications[0].notifications[0].subject.state, - ).toBe('DUPLICATE'); - expect( - result.current.notifications[0].notifications[1].subject.state, - ).toBe('OPEN'); - expect( - result.current.notifications[0].notifications[2].subject.state, - ).toBe('OUTDATED'); - expect( - result.current.notifications[0].notifications[3].subject.state, - ).toBe('REOPENED'); - expect( - result.current.notifications[0].notifications[4].subject.state, - ).toBe('RESOLVED'); - expect( - result.current.notifications[0].notifications[5].subject.state, - ).toBe('OPEN'); + const resultNotifications = result.current.notifications[0]; + + expect(resultNotifications.notifications.length).toBe(7); + expect(resultNotifications.notifications[0].subject.state).toBe( + 'ANSWERED', + ); + expect(resultNotifications.notifications[1].subject.state).toBe( + 'DUPLICATE', + ); + expect(resultNotifications.notifications[2].subject.state).toBe('OPEN'); + expect(resultNotifications.notifications[3].subject.state).toBe( + 'OUTDATED', + ); + expect(resultNotifications.notifications[4].subject.state).toBe( + 'REOPENED', + ); + expect(resultNotifications.notifications[5].subject.state).toBe( + 'RESOLVED', + ); + expect(resultNotifications.notifications[6].subject.state).toBe('OPEN'); }); }); }); From 11e777dee19c0d940e48404f157c1b396069e280 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 27 Feb 2024 11:34:20 -0500 Subject: [PATCH 8/9] refactor mocks out --- src/__mocks__/mockedData.ts | 81 ++++++++++++++++++++++++++++ src/hooks/useNotifications.test.ts | 84 +----------------------------- 2 files changed, 83 insertions(+), 82 deletions(-) diff --git a/src/__mocks__/mockedData.ts b/src/__mocks__/mockedData.ts index cfa1ef9bc..bad2dd7b9 100644 --- a/src/__mocks__/mockedData.ts +++ b/src/__mocks__/mockedData.ts @@ -497,3 +497,84 @@ export const mockedGraphQLResponse: GraphQLSearch = }, }, }; + + + export const mockedDiscussionNotifications = [ + { + id: 1, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is an answered discussion', + type: 'Discussion', + }, + }, + { + id: 2, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a duplicate discussion', + type: 'Discussion', + }, + }, + { + id: 3, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is an open discussion', + type: 'Discussion', + }, + }, + { + id: 4, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is nm outdated discussion', + type: 'Discussion', + }, + }, + { + id: 5, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a reopened discussion', + type: 'Discussion', + }, + }, + { + id: 6, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a resolved discussion', + type: 'Discussion', + }, + }, + { + id: 7, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a default discussion', + type: 'Discussion', + }, + }, + ]; \ No newline at end of file diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index 3f29e5af3..2720ed0ff 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -3,7 +3,7 @@ import axios from 'axios'; import nock from 'nock'; import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; -import { mockedUser } from '../__mocks__/mockedData'; +import { mockedDiscussionNotifications, mockedUser } from '../__mocks__/mockedData'; import { AuthState } from '../types'; import { useNotifications } from './useNotifications'; @@ -289,89 +289,9 @@ describe('hooks/useNotifications.ts', () => { user: mockedUser, }; - const notifications = [ - { - id: 1, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is an answered discussion', - type: 'Discussion', - }, - }, - { - id: 2, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is a duplicate discussion', - type: 'Discussion', - }, - }, - { - id: 3, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is an open discussion', - type: 'Discussion', - }, - }, - { - id: 4, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is nm outdated discussion', - type: 'Discussion', - }, - }, - { - id: 5, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is a reopened discussion', - type: 'Discussion', - }, - }, - { - id: 6, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is a resolved discussion', - type: 'Discussion', - }, - }, - { - id: 7, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is a default discussion', - type: 'Discussion', - }, - }, - ]; - nock('https://api.github.com') .get('/notifications?participating=false') - .reply(200, notifications); + .reply(200, mockedDiscussionNotifications); nock('https://api.github.com') .post('/graphql') From 22be07c0842d8510e7d3a3e60b4754a68518072c Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 27 Feb 2024 11:36:39 -0500 Subject: [PATCH 9/9] refactor mocks out --- src/__mocks__/mockedData.ts | 145 ++++++++++++++--------------- src/hooks/useNotifications.test.ts | 5 +- 2 files changed, 76 insertions(+), 74 deletions(-) diff --git a/src/__mocks__/mockedData.ts b/src/__mocks__/mockedData.ts index bad2dd7b9..24f87f73c 100644 --- a/src/__mocks__/mockedData.ts +++ b/src/__mocks__/mockedData.ts @@ -498,83 +498,82 @@ export const mockedGraphQLResponse: GraphQLSearch = }, }; - - export const mockedDiscussionNotifications = [ - { - id: 1, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is an answered discussion', - type: 'Discussion', - }, +export const mockedDiscussionNotifications = [ + { + id: 1, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', }, - { - id: 2, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is a duplicate discussion', - type: 'Discussion', - }, + subject: { + title: 'This is an answered discussion', + type: 'Discussion', }, - { - id: 3, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is an open discussion', - type: 'Discussion', - }, + }, + { + id: 2, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', }, - { - id: 4, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is nm outdated discussion', - type: 'Discussion', - }, + subject: { + title: 'This is a duplicate discussion', + type: 'Discussion', }, - { - id: 5, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is a reopened discussion', - type: 'Discussion', - }, + }, + { + id: 3, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', }, - { - id: 6, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is a resolved discussion', - type: 'Discussion', - }, + subject: { + title: 'This is an open discussion', + type: 'Discussion', }, - { - id: 7, - updated_at: '2024-02-26T00:00:00Z', - repository: { - full_name: 'some/repo', - }, - subject: { - title: 'This is a default discussion', - type: 'Discussion', - }, + }, + { + id: 4, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is nm outdated discussion', + type: 'Discussion', + }, + }, + { + id: 5, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a reopened discussion', + type: 'Discussion', + }, + }, + { + id: 6, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', }, - ]; \ No newline at end of file + subject: { + title: 'This is a resolved discussion', + type: 'Discussion', + }, + }, + { + id: 7, + updated_at: '2024-02-26T00:00:00Z', + repository: { + full_name: 'some/repo', + }, + subject: { + title: 'This is a default discussion', + type: 'Discussion', + }, + }, +]; diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index 2720ed0ff..4285d006a 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -3,7 +3,10 @@ import axios from 'axios'; import nock from 'nock'; import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; -import { mockedDiscussionNotifications, mockedUser } from '../__mocks__/mockedData'; +import { + mockedDiscussionNotifications, + mockedUser, +} from '../__mocks__/mockedData'; import { AuthState } from '../types'; import { useNotifications } from './useNotifications';