forked from cakeinpanic/jira-description-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.test.ts
executable file
·87 lines (70 loc) · 3.79 KB
/
utils.test.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
import { HIDDEN_MARKER_END, HIDDEN_MARKER_START, WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS } from '../src/constants';
import { getJIRAIssueKeyByDefaultRegexp, getJIRAIssueKeysByCustomRegexp, getPRDescription, shouldSkipBranch } from '../src/utils';
jest.spyOn(console, 'log').mockImplementation(); // avoid actual console.log in test output
describe('shouldSkipBranch()', () => {
it('should recognize bot PRs', () => {
expect(shouldSkipBranch('dependabot/npm_and_yarn/types/react-dom-16.9.6')).toBe(true);
expect(shouldSkipBranch('feature/add-dependabot-config')).toBe(false);
});
it('should handle custom ignore patterns', () => {
expect(shouldSkipBranch('bar', '^bar')).toBeTruthy();
expect(shouldSkipBranch('foobar', '^bar')).toBeFalsy();
expect(shouldSkipBranch('bar', '[0-9]{2}')).toBeFalsy();
expect(shouldSkipBranch('bar', '')).toBeFalsy();
expect(shouldSkipBranch('f00', '[0-9]{2}')).toBeTruthy();
const customBranchRegex = '^(production-release|master|release/v\\d+)$';
expect(shouldSkipBranch('production-release', customBranchRegex)).toBeTruthy();
expect(shouldSkipBranch('master', customBranchRegex)).toBeTruthy();
expect(shouldSkipBranch('release/v77', customBranchRegex)).toBeTruthy();
expect(shouldSkipBranch('release/very-important-feature', customBranchRegex)).toBeFalsy();
expect(shouldSkipBranch('')).toBeFalsy();
});
});
describe('getJIRAIssueKeys()', () => {
it('gets jira key from different strings', () => {
expect(getJIRAIssueKeyByDefaultRegexp('fix/login-protocol-es-43')).toEqual('ES-43');
expect(getJIRAIssueKeyByDefaultRegexp('fix/login-protocol-ES-43')).toEqual('ES-43');
expect(getJIRAIssueKeyByDefaultRegexp('[ES-43, ES-15] Feature description')).toEqual('ES-43');
expect(getJIRAIssueKeyByDefaultRegexp('feature/missingKey')).toEqual(null);
expect(getJIRAIssueKeyByDefaultRegexp('')).toEqual(null);
});
});
describe('getJIRAIssueKeysByCustomRegexp() gets jira keys from different strings', () => {
it('with project name', () => {
expect(getJIRAIssueKeysByCustomRegexp('law-18,345', '^LAW-??(\\d+)', 'LAW')).toEqual('LAW-18');
//expect(getJIRAIssueKeysByCustomRegexp('fix/login-protocol-es-43', '^\\d+', 'QQ')).toEqual(null);
//expect(getJIRAIssueKeysByCustomRegexp('43-login-protocol', '^\\d+', 'QQ')).toEqual('QQ-43');
});
it('without project name', () => {
expect(getJIRAIssueKeysByCustomRegexp('18,345', '\\d+')).toEqual('18');
expect(getJIRAIssueKeysByCustomRegexp('fix/login-protocol-es-43', 'es-\\d+')).toEqual('ES-43');
});
it('with grouped value in regexp', () => {
expect(getJIRAIssueKeysByCustomRegexp('fix/login-protocol-es-43', '(es-\\d+)$')).toEqual('ES-43');
expect(getJIRAIssueKeysByCustomRegexp('fix/login-20-in-14', '-(IN-\\d+)')).toEqual('IN-14');
expect(getJIRAIssueKeysByCustomRegexp('fix/login-20-in-14', 'in-(\\d+)', 'PRJ')).toEqual('PRJ-20');
});
});
describe('getPRDescription()', () => {
it('should prepend issue info with hidden markers to old PR body', () => {
const oldPRBody = 'old PR description body';
const issueInfo = 'new info about jira task';
const description = getPRDescription(oldPRBody, issueInfo);
expect(description).toEqual(`${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${HIDDEN_MARKER_START}
${issueInfo}
${HIDDEN_MARKER_END}
${oldPRBody}`);
});
it('should replace issue info', () => {
const oldPRBodyInformation = 'old PR description body';
const oldPRBody = `${HIDDEN_MARKER_START}Here is some old issue information${HIDDEN_MARKER_END}${oldPRBodyInformation}`;
const issueInfo = 'new info about jira task';
const description = getPRDescription(oldPRBody, issueInfo);
expect(description).toEqual(`${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${HIDDEN_MARKER_START}
${issueInfo}
${HIDDEN_MARKER_END}
${oldPRBodyInformation}`);
});
});