-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpr-jira-issue-link.test.js
More file actions
125 lines (89 loc) · 3.43 KB
/
Copy pathpr-jira-issue-link.test.js
File metadata and controls
125 lines (89 loc) · 3.43 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
122
123
124
125
const { extractIssuesSection, validatePullRequestBody } = require('./pr-jira-issue-link');
describe('PR Jira issue link validation', () => {
it('extracts the Jira Issue(s) section from the PR body', () => {
const body = `## Description of change
- Update dependencies.
## Jira Issue(s)
* https://jira.acf.gov/browse/TTAHUB-5247
## Checklists
- [ ] Code is meaningfully tested
`;
expect(extractIssuesSection(body)).toContain('TTAHUB-5247');
});
it('passes when the Jira Issue(s) section contains a valid Jira issue link', () => {
const result = validatePullRequestBody(`## Jira Issue(s)
* https://jira.acf.gov/browse/TTAHUB-5247
`);
expect(result).toEqual({
valid: true,
jiraKeys: ['TTAHUB-5247'],
message: 'Validated Jira issue link(s): TTAHUB-5247',
});
});
it('fails when the Jira Issue(s) section is missing', () => {
const result = validatePullRequestBody(`## Description of change
- Update a dependency.
`);
expect(result.valid).toBe(false);
expect(result.message).toContain('add the approved Jira issue link');
});
it('fails when the placeholder is still present', () => {
const result = validatePullRequestBody(`## Jira Issue(s)
* https://jira.acf.gov/browse/TTAHUB-0
`);
expect(result.valid).toBe(false);
expect(result.message).toContain('remove the TTAHUB-0 placeholder');
});
it('fails when the placeholder and a real issue link both appear', () => {
const result = validatePullRequestBody(`## Jira Issue(s)
* https://jira.acf.gov/browse/TTAHUB-0
* https://jira.acf.gov/browse/TTAHUB-5247
`);
expect(result.valid).toBe(false);
expect(result.message).toContain('remove the TTAHUB-0 placeholder');
});
it('ignores the template comment that mentions TTAHUB-0 when a real issue link is present', () => {
const result = validatePullRequestBody(`## Jira Issue(s)
<!-- Link the approved Jira issue for this PR. Replace TTAHUB-0 before requesting review. -->
* https://jira.acf.gov/browse/TTAHUB-5247
`);
expect(result).toEqual({
valid: true,
jiraKeys: ['TTAHUB-5247'],
message: 'Validated Jira issue link(s): TTAHUB-5247',
});
});
it('fails when the Jira Issue(s) section contains only a bare Jira key', () => {
const result = validatePullRequestBody(`## Jira Issue(s)
* TTAHUB-5247
`);
expect(result.valid).toBe(false);
expect(result.message).toContain(
'Use the full https://jira.acf.gov/browse/TTAHUB-#### issue link format'
);
});
it('fails when the Jira issue link is only outside the Jira Issue(s) section', () => {
const result = validatePullRequestBody(`## Description of change
- https://jira.acf.gov/browse/TTAHUB-5247 update dependencies.
## Jira Issue(s)
* None provided yet
`);
expect(result.valid).toBe(false);
expect(result.message).toContain('Jira Issue(s)');
expect(result.message).toContain('TTAHUB-5247');
});
it('accepts the fallback Issue heading used by some handwritten PR bodies', () => {
const result = validatePullRequestBody(`## Issue
* https://jira.acf.gov/browse/TTAHUB-5247
`);
expect(result.valid).toBe(true);
expect(result.jiraKeys).toEqual(['TTAHUB-5247']);
});
it('accepts the previous Issue(s) heading for backward compatibility', () => {
const result = validatePullRequestBody(`## Issue(s)
* https://jira.acf.gov/browse/TTAHUB-5247
`);
expect(result.valid).toBe(true);
expect(result.jiraKeys).toEqual(['TTAHUB-5247']);
});
});