Skip to content

Commit 7f17bb0

Browse files
committed
refactor: tests
Signed-off-by: Adam Setch <[email protected]>
1 parent df570ea commit 7f17bb0

File tree

2 files changed

+283
-101
lines changed

2 files changed

+283
-101
lines changed

src/renderer/utils/notifications/handlers/issue.test.ts

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { mockSettings } from '../../../__mocks__/state-mocks';
99
import { createPartialMockUser } from '../../../__mocks__/user-mocks';
1010
import type { Link } from '../../../types';
1111
import type { Notification } from '../../../typesGitHub';
12+
import type { FetchIssueByNumberQuery } from '../../api/graphql/generated/graphql';
1213
import { issueHandler } from './issue';
1314

1415
describe('renderer/utils/notifications/handlers/issue.ts', () => {
@@ -34,58 +35,74 @@ describe('renderer/utils/notifications/handlers/issue.ts', () => {
3435

3536
it('open issue state', async () => {
3637
nock('https://api.github.com')
37-
.get('/repos/gitify-app/notifications-test/issues/1')
38+
.post('/graphql')
3839
.reply(200, {
39-
number: 123,
40-
state: 'open',
41-
user: mockAuthor,
42-
labels: [],
40+
data: {
41+
repository: {
42+
issue: {
43+
__typename: 'Issue',
44+
number: 123,
45+
title: 'PR Title',
46+
state: 'OPEN',
47+
url: 'https://github.com/gitify-app/noticiation-test/issues/123',
48+
author: mockAuthor,
49+
labels: { nodes: [] },
50+
comments: { totalCount: 0, nodes: [] },
51+
} as FetchIssueByNumberQuery['repository']['issue'],
52+
},
53+
},
4354
});
4455

45-
nock('https://api.github.com')
46-
.get('/repos/gitify-app/notifications-test/issues/comments/302888448')
47-
.reply(200, { user: mockCommenter });
48-
4956
const result = await issueHandler.enrich(mockNotification, mockSettings);
5057

5158
expect(result).toEqual({
5259
number: 123,
53-
state: 'open',
60+
state: 'OPEN',
5461
user: {
55-
login: mockCommenter.login,
56-
html_url: mockCommenter.html_url,
57-
avatar_url: mockCommenter.avatar_url,
58-
type: mockCommenter.type,
62+
login: mockAuthor.login,
63+
html_url: mockAuthor.html_url,
64+
avatar_url: mockAuthor.avatar_url,
65+
type: mockAuthor.type,
5966
},
67+
comments: 0,
68+
htmlUrl: 'https://github.com/gitify-app/noticiation-test/issues/123',
6069
labels: [],
6170
});
6271
});
6372

6473
it('closed issue state', async () => {
6574
nock('https://api.github.com')
66-
.get('/repos/gitify-app/notifications-test/issues/1')
75+
.post('/graphql')
6776
.reply(200, {
68-
number: 123,
69-
state: 'closed',
70-
user: mockAuthor,
71-
labels: [],
77+
data: {
78+
repository: {
79+
issue: {
80+
__typename: 'Issue',
81+
number: 123,
82+
title: 'PR Title',
83+
state: 'CLOSED',
84+
url: 'https://github.com/gitify-app/noticiation-test/issues/123',
85+
author: mockAuthor,
86+
labels: { nodes: [] },
87+
comments: { totalCount: 0, nodes: [] },
88+
} as FetchIssueByNumberQuery['repository']['issue'],
89+
},
90+
},
7291
});
7392

74-
nock('https://api.github.com')
75-
.get('/repos/gitify-app/notifications-test/issues/comments/302888448')
76-
.reply(200, { user: mockCommenter });
77-
7893
const result = await issueHandler.enrich(mockNotification, mockSettings);
7994

8095
expect(result).toEqual({
8196
number: 123,
82-
state: 'closed',
97+
state: 'CLOSED',
8398
user: {
84-
login: mockCommenter.login,
85-
html_url: mockCommenter.html_url,
86-
avatar_url: mockCommenter.avatar_url,
87-
type: mockCommenter.type,
99+
login: mockAuthor.login,
100+
html_url: mockAuthor.html_url,
101+
avatar_url: mockAuthor.avatar_url,
102+
type: mockAuthor.type,
88103
},
104+
comments: 0,
105+
htmlUrl: 'https://github.com/gitify-app/noticiation-test/issues/123',
89106
labels: [],
90107
});
91108
});

0 commit comments

Comments
 (0)