-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathcommit.test.ts
More file actions
105 lines (89 loc) · 3.49 KB
/
commit.test.ts
File metadata and controls
105 lines (89 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import axios from 'axios';
import nock from 'nock';
import { createSubjectMock } from '../../../__mocks__/notifications-mocks';
import {
partialMockNotification,
partialMockUser,
} from '../../../__mocks__/partial-mocks';
import { mockSettings } from '../../../__mocks__/state-mocks';
import type { Link } from '../../../types';
import { commitHandler } from './commit';
describe('renderer/utils/notifications/handlers/commit.ts', () => {
describe('enrich', () => {
const mockAuthor = partialMockUser('some-author');
const mockCommenter = partialMockUser('some-commenter');
beforeEach(() => {
// axios will default to using the XHR adapter which can't be intercepted
// by nock. So, configure axios to use the node adapter.
axios.defaults.adapter = 'http';
});
it('get commit commenter', async () => {
const mockNotification = partialMockNotification({
title: 'This is a commit with comments',
type: 'Commit',
url: 'https://api.github.com/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8' as Link,
latest_comment_url:
'https://api.github.com/repos/gitify-app/notifications-test/comments/141012658' as Link,
});
nock('https://api.github.com')
.get(
'/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8',
)
.reply(200, { author: mockAuthor });
nock('https://api.github.com')
.get('/repos/gitify-app/notifications-test/comments/141012658')
.reply(200, { user: mockCommenter });
const result = await commitHandler.enrich(mockNotification, mockSettings);
expect(result).toEqual({
state: null,
user: {
login: mockCommenter.login,
html_url: mockCommenter.html_url,
avatar_url: mockCommenter.avatar_url,
type: mockCommenter.type,
},
});
});
it('get commit without commenter', async () => {
const mockNotification = partialMockNotification({
title: 'This is a commit with comments',
type: 'Commit',
url: 'https://api.github.com/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8' as Link,
latest_comment_url: null,
});
nock('https://api.github.com')
.get(
'/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8',
)
.reply(200, { author: mockAuthor });
const result = await commitHandler.enrich(mockNotification, mockSettings);
expect(result).toEqual({
state: null,
user: {
login: mockAuthor.login,
html_url: mockAuthor.html_url,
avatar_url: mockAuthor.avatar_url,
type: mockAuthor.type,
},
});
});
it('return early if commit state filtered', async () => {
const mockNotification = partialMockNotification({
title: 'This is a commit with comments',
type: 'Commit',
url: 'https://api.github.com/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8' as Link,
latest_comment_url: null,
});
const result = await commitHandler.enrich(mockNotification, {
...mockSettings,
filterStates: ['closed'],
});
expect(result).toEqual(null);
});
});
it('iconType', () => {
expect(
commitHandler.iconType(createSubjectMock({ type: 'Commit' })).displayName,
).toBe('GitCommitIcon');
});
});