forked from agrc/reminder-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
129 lines (109 loc) · 3.06 KB
/
index.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const {
getRemindersFromBody,
getPastDueReminders,
createCommentsMetadata,
markAsNotified,
} = require('./utilities');
describe('getRemindersFromBody', () => {
test('can find reminder issues', () => {
const body = `testing
<!-- bot: {"reminders":[{"id":1,"who":"stdavis","what":"celebrate","when":"2020-06-24T09:28:33.000Z"}]} -->`;
const expected = {
id: 1,
who: 'stdavis',
what: 'celebrate',
when: '2020-06-24T09:28:33.000Z',
};
expect(getRemindersFromBody(body)).toEqual([expected]);
});
test('Can handle body being null', () => {
const body = null;
expect(getRemindersFromBody(body)).toEqual([]);
});
});
describe('getPastDueReminders', () => {
test('returns past due reminders', () => {
const today = new Date(2000, 1, 1);
const items = [
{
issueNumber: 1,
reminder: {
when: '2001-06-24T09:00:00.000Z',
},
},
{
issueNumber: 2,
reminder: {
when: '1999-06-24T09:00:00.000Z',
},
},
];
const results = getPastDueReminders(today, items);
expect(results.length).toBe(1);
expect(results[0].issueNumber).toBe(2);
});
test('can handle malformed date', () => {
const today = new Date(2000, 1, 1);
const items = [
{
issueNumber: 1,
reminder: {
when: 'blah',
},
},
{
issueNumber: 2,
reminder: {
when: '1999-06-24T09:00:00.000Z',
},
},
];
const results = getPastDueReminders(today, items);
expect(results.length).toBe(1);
expect(results[0].issueNumber).toBe(2);
});
});
describe('createComments', () => {
test('creates comments parameters array', () => {
const items = [
{
issueNumber: 1,
reminder: {
who: 'steve',
what: 'to something',
},
},
{
issueNumber: 2,
reminder: {
who: 'scott',
what: 'to something else',
},
},
];
const result = createCommentsMetadata(items);
expect(result[0]).toEqual({
issue_number: 1,
body: ':wave: @steve, to something',
});
expect(result.length).toBe(2);
});
});
describe('markAsNotified', () => {
test('removes reminder from body but leaves active ones', () => {
const body = `testing
<!-- bot: {"reminders":[{"id":1,"who":"stdavis","what":"celebrate","when":"2020-06-24T09:28:33.000Z"},{"id":2,"who":"stdavis","what":"celebrate","when":"2020-06-24T09:28:33.000Z"}]} -->`;
const expected = {
body: `testing
<!-- bot: {"reminders":[{"id":2,"who":"stdavis","what":"celebrate","when":"2020-06-24T09:28:33.000Z"}]} -->`,
hasActive: true,
};
expect(markAsNotified(body, 1)).toEqual(expected);
});
test('removes reminder from body', () => {
const body = `testing
<!-- bot: {"reminders":[{"id":1,"who":"stdavis","what":"celebrate","when":"2020-06-24T09:28:33.000Z"}]} -->`;
const expected = { body: 'testing', hasActive: false };
expect(markAsNotified(body, 1)).toEqual(expected);
});
});