forked from actions/stale
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue.spec.ts
298 lines (246 loc) · 8.02 KB
/
issue.spec.ts
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import {IUserAssignee} from '../interfaces/assignee';
import {IIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {ILabel} from '../interfaces/label';
import {IMilestone} from '../interfaces/milestone';
import {Issue} from './issue';
describe('Issue', (): void => {
let issue: Issue;
let optionsInterface: IIssuesProcessorOptions;
let issueInterface: IIssue;
beforeEach((): void => {
optionsInterface = {
ascending: false,
closeIssueLabel: '',
closeIssueMessage: '',
closePrLabel: '',
closePrMessage: '',
daysBeforeClose: 0,
daysBeforeIssueClose: 0,
daysBeforeIssueStale: 0,
daysBeforePrClose: 0,
daysBeforePrStale: 0,
daysBeforeStale: 0,
debugOnly: false,
deleteBranch: false,
exemptIssueLabels: '',
exemptPrLabels: '',
onlyLabels: '',
onlyIssueLabels: '',
onlyPrLabels: '',
anyOfLabels: '',
anyOfIssueLabels: '',
anyOfPrLabels: '',
operationsPerRun: 0,
removeStaleWhenUpdated: false,
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
repoToken: '',
staleIssueMessage: '',
stalePrMessage: '',
startDate: undefined,
stalePrLabel: 'dummy-stale-pr-label',
staleIssueLabel: 'dummy-stale-issue-label',
exemptMilestones: '',
exemptIssueMilestones: '',
exemptPrMilestones: '',
exemptAllMilestones: false,
exemptAllIssueMilestones: undefined,
exemptAllPrMilestones: undefined,
exemptAssignees: '',
exemptIssueAssignees: '',
exemptPrAssignees: '',
exemptAllAssignees: false,
exemptAllIssueAssignees: undefined,
exemptAllPrAssignees: undefined,
enableStatistics: false,
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: '',
ignoreUpdates: false,
ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined,
exemptDraftPr: false,
closeAsNotPlanned: undefined
};
issueInterface = {
title: 'dummy-title',
number: 8,
created_at: 'dummy-created-at',
updated_at: 'dummy-updated-at',
labels: [
{
name: 'dummy-name'
}
],
pull_request: {},
state: 'dummy-state',
locked: false,
milestone: {
title: 'dummy-milestone'
},
assignees: [
{
login: 'dummy-login',
type: 'User'
}
]
};
issue = new Issue(optionsInterface, issueInterface);
});
describe('constructor()', (): void => {
it('should set the title with the given issue title', (): void => {
expect.assertions(1);
expect(issue.title).toStrictEqual('dummy-title');
});
it('should set the number with the given issue number', (): void => {
expect.assertions(1);
expect(issue.number).toStrictEqual(8);
});
it('should set the created_at with the given issue created_at', (): void => {
expect.assertions(1);
expect(issue.created_at).toStrictEqual('dummy-created-at');
});
it('should set the updated_at with the given issue updated_at', (): void => {
expect.assertions(1);
expect(issue.updated_at).toStrictEqual('dummy-updated-at');
});
it('should set the labels with the given issue labels', (): void => {
expect.assertions(1);
expect(issue.labels).toStrictEqual([
{
name: 'dummy-name'
} as ILabel
]);
});
it('should set the pull_request with the given issue pull_request', (): void => {
expect.assertions(1);
expect(issue.pull_request).toStrictEqual({});
});
it('should set the state with the given issue state', (): void => {
expect.assertions(1);
expect(issue.state).toStrictEqual('dummy-state');
});
it('should set the locked with the given issue locked', (): void => {
expect.assertions(1);
expect(issue.locked).toStrictEqual(false);
});
it('should set the milestone with the given issue milestone', (): void => {
expect.assertions(1);
expect(issue.milestone).toStrictEqual({
title: 'dummy-milestone'
} as IMilestone);
});
it('should set the assignees with the given issue assignees', (): void => {
expect.assertions(1);
expect(issue.assignees).toStrictEqual([
{
login: 'dummy-login',
type: 'User'
} as IUserAssignee
]);
});
describe('when the given issue does not contains the stale label', (): void => {
beforeEach((): void => {
issueInterface.pull_request = undefined;
issueInterface.labels = [];
issue = new Issue(optionsInterface, issueInterface);
});
it('should set the isStale to false', (): void => {
expect.assertions(1);
expect(issue.isStale).toStrictEqual(false);
});
});
describe('when the given issue contains the stale label', (): void => {
beforeEach((): void => {
issueInterface.pull_request = undefined;
issueInterface.labels = [
{
name: 'dummy-stale-issue-label'
} as ILabel
];
issue = new Issue(optionsInterface, issueInterface);
});
it('should set the isStale to true', (): void => {
expect.assertions(1);
expect(issue.isStale).toStrictEqual(true);
});
});
});
describe('get isPullRequest', (): void => {
describe('when the issue pull_request is not set', (): void => {
beforeEach((): void => {
issueInterface.pull_request = undefined;
issue = new Issue(optionsInterface, issueInterface);
});
it('should return false', (): void => {
expect.assertions(1);
const result = issue.isPullRequest;
expect(result).toStrictEqual(false);
});
});
describe('when the issue pull_request is set', (): void => {
beforeEach((): void => {
issueInterface.pull_request = {};
issue = new Issue(optionsInterface, issueInterface);
});
it('should return true', (): void => {
expect.assertions(1);
const result = issue.isPullRequest;
expect(result).toStrictEqual(true);
});
});
});
describe('get staleLabel', (): void => {
describe('when the issue is not a pull request', (): void => {
beforeEach((): void => {
issueInterface.pull_request = undefined;
issue = new Issue(optionsInterface, issueInterface);
});
it('should return the issue stale label', (): void => {
expect.assertions(1);
const result = issue.staleLabel;
expect(result).toStrictEqual('dummy-stale-issue-label');
});
});
describe('when the given issue is a pull request', (): void => {
beforeEach((): void => {
issueInterface.pull_request = {};
issue = new Issue(optionsInterface, issueInterface);
});
it('should return the pull request stale label', (): void => {
expect.assertions(1);
const result = issue.staleLabel;
expect(result).toStrictEqual('dummy-stale-pr-label');
});
});
});
describe('get hasAssignees', (): void => {
describe('when the issue has no assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
issue = new Issue(optionsInterface, issueInterface);
});
it('should return false', (): void => {
expect.assertions(1);
const result = issue.hasAssignees;
expect(result).toStrictEqual(false);
});
});
describe('when the issue has at least one assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
login: 'dummy-login',
type: 'User'
}
];
issue = new Issue(optionsInterface, issueInterface);
});
it('should return true', (): void => {
expect.assertions(1);
const result = issue.hasAssignees;
expect(result).toStrictEqual(true);
});
});
});
});