-
Notifications
You must be signed in to change notification settings - Fork 6
/
usersToNotify.test.js
73 lines (71 loc) · 1.89 KB
/
usersToNotify.test.js
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
const { usersToNotify } = require('./usersToNotify');
const issue = {
state: 'open',
user: { login: 'hypnosphi' },
assignees: []
};
describe('notification', () => {
it('should notify nobody when the issue is closed', () => {
expect(
usersToNotify({
matchingUsers: ['shilman'],
fullIssue: { ...issue, state: 'closed' },
issueComments: []
})
).toEqual([]);
});
it("should notify nobody when the it's a draft PR", () => {
expect(
usersToNotify({
matchingUsers: ['shilman'],
fullIssue: { ...issue, draft: true },
issueComments: []
})
).toEqual([]);
});
it('should notify nobody when the issue is assigned', () => {
expect(
usersToNotify({
matchingUsers: ['ndelangen'],
fullIssue: { ...issue, assignees: [{ login: 'shilman' }] },
issueComments: []
})
).toEqual([]);
});
it('should notify matching users', () => {
expect(
usersToNotify({
matchingUsers: ['igor-dv', 'shilman'],
fullIssue: issue,
issueComments: []
})
).toEqual(['igor-dv', 'shilman']);
});
it('should skip users that have already commented', () => {
expect(
usersToNotify({
matchingUsers: ['igor-dv', 'shilman'],
fullIssue: issue,
issueComments: [{ user: { login: 'shilman' } }]
})
).toEqual(['igor-dv']);
});
it('should skip issue author', () => {
expect(
usersToNotify({
matchingUsers: ['domyen', 'shilman'],
fullIssue: { ...issue, user: { login: 'domyen' } },
issueComments: [{ user: { login: 'shilman' } }]
})
).toEqual([]);
});
it('should uniquify and sort users', () => {
expect(
usersToNotify({
matchingUsers: ['tmeasday', 'shilman', 'tmeasday'],
fullIssue: issue,
issueComments: []
})
).toEqual(['shilman', 'tmeasday']);
});
});