Skip to content

Commit

Permalink
refactor: remove unnecessary logic
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed May 12, 2024
1 parent 358c0f7 commit c62f9ce
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 65 deletions.
15 changes: 0 additions & 15 deletions src/__mocks__/mockedData.ts
Expand Up @@ -426,7 +426,6 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
search: {
nodes: [
{
viewerSubscription: 'SUBSCRIBED',
title: '1.16.0',
isAnswered: false,
stateReason: 'OPEN',
Expand All @@ -439,20 +438,6 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
},
comments: mockDiscussionComments,
},
{
viewerSubscription: 'IGNORED',
title: '1.16.0',
isAnswered: false,
stateReason: 'ANSWERED',
url: 'https://github.com/gitify-app/notifications-test/discussions/123',
author: {
login: 'discussion-creator',
url: 'https://github.com/discussion-creator',
avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4',
type: 'User',
},
comments: mockDiscussionComments,
},
],
},
},
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useNotifications.test.ts
Expand Up @@ -319,7 +319,6 @@ describe('hooks/useNotifications.ts', () => {
nodes: [
{
title: 'This is a Discussion.',
viewerSubscription: 'SUBSCRIBED',
stateReason: null,
isAnswered: true,
url: 'https://github.com/gitify-app/notifications-test/discussions/612',
Expand Down
3 changes: 0 additions & 3 deletions src/typesGitHub.ts
Expand Up @@ -59,8 +59,6 @@ export type StateType =
| IssueStateReasonType
| PullRequestStateType;

export type ViewerSubscription = 'IGNORED' | 'SUBSCRIBED' | 'UNSUBSCRIBED';

export type CheckSuiteStatus =
| 'action_required'
| 'cancelled'
Expand Down Expand Up @@ -450,7 +448,6 @@ export interface GraphQLSearch<T> {
}

export interface Discussion {
viewerSubscription: ViewerSubscription;
title: string;
stateReason: DiscussionStateType;
isAnswered: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/api/client.ts
Expand Up @@ -254,7 +254,7 @@ export async function searchDiscussions(
notification.repository.full_name,
notification.subject.title,
),
firstDiscussions: 5,
firstDiscussions: 1,
lastComments: 1,
lastReplies: 1,
},
Expand Down
1 change: 0 additions & 1 deletion src/utils/api/graphql/discussions.ts
Expand Up @@ -31,7 +31,6 @@ export const QUERY_SEARCH_DISCUSSIONS = gql`
search(query:$queryStatement, type: DISCUSSION, first: $firstDiscussions) {
nodes {
... on Discussion {
viewerSubscription
title
stateReason
isAnswered
Expand Down
6 changes: 1 addition & 5 deletions src/utils/helpers.ts
Expand Up @@ -116,11 +116,7 @@ export async function fetchDiscussion(
try {
const response = await searchDiscussions(notification, token);

const discussions = response.data?.data.search.nodes.filter(
(discussion) => discussion.title === notification.subject.title,
);

return discussions[0] ?? null;
return response.data?.data.search.nodes[0] ?? null;
} catch (err) {}
}

Expand Down
45 changes: 6 additions & 39 deletions src/utils/subject.test.ts
Expand Up @@ -12,7 +12,6 @@ import type {
DiscussionStateType,
Notification,
Repository,
ViewerSubscription,
} from '../typesGitHub';
import {
getCheckSuiteAttributes,
Expand Down Expand Up @@ -239,7 +238,7 @@ describe('utils/subject.ts', () => {
.reply(200, {
data: {
search: {
nodes: [mockDiscussionNode('SUBSCRIBED', null, true)],
nodes: [mockDiscussionNode(null, true)],
},
},
});
Expand All @@ -266,7 +265,7 @@ describe('utils/subject.ts', () => {
.reply(200, {
data: {
search: {
nodes: [mockDiscussionNode('SUBSCRIBED', 'DUPLICATE', false)],
nodes: [mockDiscussionNode('DUPLICATE', false)],
},
},
});
Expand All @@ -293,7 +292,7 @@ describe('utils/subject.ts', () => {
.reply(200, {
data: {
search: {
nodes: [mockDiscussionNode('SUBSCRIBED', null, false)],
nodes: [mockDiscussionNode(null, false)],
},
},
});
Expand All @@ -320,7 +319,7 @@ describe('utils/subject.ts', () => {
.reply(200, {
data: {
search: {
nodes: [mockDiscussionNode('SUBSCRIBED', 'OUTDATED', false)],
nodes: [mockDiscussionNode('OUTDATED', false)],
},
},
});
Expand All @@ -347,7 +346,7 @@ describe('utils/subject.ts', () => {
.reply(200, {
data: {
search: {
nodes: [mockDiscussionNode('SUBSCRIBED', 'REOPENED', false)],
nodes: [mockDiscussionNode('REOPENED', false)],
},
},
});
Expand All @@ -374,7 +373,7 @@ describe('utils/subject.ts', () => {
.reply(200, {
data: {
search: {
nodes: [mockDiscussionNode('SUBSCRIBED', 'RESOLVED', true)],
nodes: [mockDiscussionNode('RESOLVED', true)],
},
},
});
Expand All @@ -394,36 +393,6 @@ describe('utils/subject.ts', () => {
},
});
});

it('filtered response by subscribed', async () => {
nock('https://api.github.com')
.post('/graphql')
.reply(200, {
data: {
search: {
nodes: [
mockDiscussionNode('SUBSCRIBED', null, false),
mockDiscussionNode('IGNORED', null, true),
],
},
},
});

const result = await getGitifySubjectDetails(
mockNotification,
mockAccounts.token,
);

expect(result).toEqual({
state: 'OPEN',
user: {
login: mockDiscussionAuthor.login,
html_url: mockDiscussionAuthor.url,
avatar_url: mockDiscussionAuthor.avatar_url,
type: mockDiscussionAuthor.type,
},
});
});
});

describe('Issues', () => {
Expand Down Expand Up @@ -1176,14 +1145,12 @@ describe('utils/subject.ts', () => {
});

function mockDiscussionNode(
subscription: ViewerSubscription,
state: DiscussionStateType,
isAnswered: boolean,
): Discussion {
return {
title: 'This is a mocked discussion',
url: 'https://github.com/gitify-app/notifications-test/discussions/1',
viewerSubscription: subscription,
stateReason: state,
isAnswered: isAnswered,
author: mockDiscussionAuthor,
Expand Down

0 comments on commit c62f9ce

Please sign in to comment.