Repository navigation
Expand file tree
/
Copy pathissue.test.ts
More file actions
121 lines (106 loc) · 4.3 KB
/
Copy pathissue.test.ts
File metadata and controls
121 lines (106 loc) · 4.3 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { Issue } from '../issue';
describe('Issue', () => {
const issuePayload = {
title: 'Add feature',
number: 10,
html_url: 'https://github.com/o/r/issues/10',
body: 'Body text',
user: { login: 'bob' },
};
it('uses inputs when provided', () => {
const inputs = { action: 'opened', issue: issuePayload, eventName: 'issues' };
const i = new Issue(false, false, 1, inputs);
expect(i.title).toBe('Add feature');
expect(i.number).toBe(10);
expect(i.creator).toBe('bob');
expect(i.url).toBe('https://github.com/o/r/issues/10');
expect(i.body).toBe('Body text');
expect(i.opened).toBe(true);
expect(i.labeled).toBe(false);
expect(i.isIssue).toBe(true);
expect(i.isIssueComment).toBe(false);
});
it('returns empty values when inputs are missing', () => {
const i = new Issue(false, false, 1, undefined);
expect(i.title).toBe('');
expect(i.number).toBe(-1);
expect(i.isIssue).toBe(false);
});
it('prefers live title and body when processing a stale queued event', () => {
const issue = new Issue(true, false, 1, { action: 'opened', issue: issuePayload, eventName: 'issues' });
issue.liveTitle = 'Current normalized title';
issue.liveBody = 'Current description';
expect(issue.title).toBe('Current normalized title');
expect(issue.body).toBe('Current description');
expect(issue.inputs?.issue?.title).toBe('Add feature');
});
it('labeled and labelAdded when action is labeled', () => {
const inputs = { action: 'labeled', issue: issuePayload, label: { name: 'bug' } };
const i = new Issue(false, false, 1, inputs);
expect(i.labeled).toBe(true);
expect(i.labelAdded).toBe('bug');
});
it('isIssueComment when eventName is issue_comment', () => {
const inputs = { eventName: 'issue_comment', issue: issuePayload, comment: { id: 5, body: 'Hi', user: { login: 'alice' }, html_url: 'url' } };
const i = new Issue(false, false, 1, inputs);
expect(i.isIssueComment).toBe(true);
expect(i.isIssue).toBe(false);
expect(i.commentId).toBe(5);
expect(i.commentBody).toBe('Hi');
expect(i.commentAuthor).toBe('alice');
expect(i.commentUrl).toBe('url');
});
it('opened is true when action is reopened', () => {
const inputs = { action: 'reopened', issue: issuePayload, eventName: 'issues' };
const i = new Issue(false, false, 1, inputs);
expect(i.opened).toBe(true);
});
it('opened is false when action is closed', () => {
const i = new Issue(false, false, 1, { action: 'closed', issue: issuePayload, eventName: 'issues' });
expect(i.opened).toBe(false);
});
it('detects an issue description edit from the GitHub changes payload', () => {
const i = new Issue(false, false, 1, {
action: 'edited',
issue: issuePayload,
changes: { body: { from: 'Previous description' } },
eventName: 'issues',
});
expect(i.descriptionEdited).toBe(true);
});
it('does not treat title-only edits as description edits', () => {
const i = new Issue(false, false, 1, {
action: 'edited',
issue: issuePayload,
changes: { title: { from: 'Previous title' } },
eventName: 'issues',
});
expect(i.descriptionEdited).toBe(false);
});
it('uses the user and comment data provided in inputs', () => {
const i = new Issue(false, false, 1, {
action: 'created',
eventName: 'issue_comment',
issue: { ...issuePayload, user: { login: 'context-user' } },
comment: { id: 99, body: 'From context', user: { login: 'ctx-commenter' }, html_url: 'https://comment.url' },
});
expect(i.creator).toBe('context-user');
expect(i.commentBody).toBe('From context');
expect(i.commentAuthor).toBe('ctx-commenter');
expect(i.commentUrl).toBe('https://comment.url');
expect(i.commentId).toBe(99);
});
it('uses the label data provided in inputs', () => {
const i = new Issue(false, false, 1, { action: 'labeled', issue: issuePayload, eventName: 'issues', label: { name: 'from-inputs' } });
expect(i.labeled).toBe(true);
expect(i.labelAdded).toBe('from-inputs');
});
it('normalizes invalid issue and comment identifiers', () => {
const i = new Issue(false, false, 1, {
issue: { number: Number.NaN },
comment: { id: 0 },
});
expect(i.number).toBe(-1);
expect(i.commentId).toBe(-1);
});
});