-
Notifications
You must be signed in to change notification settings - Fork 480
Expand file tree
/
Copy pathtitle.test.ts
More file actions
143 lines (123 loc) · 3.83 KB
/
title.test.ts
File metadata and controls
143 lines (123 loc) · 3.83 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import {
getTitle,
checkAnyTitle,
checkAllTitle,
toTitleMatchConfig,
TitleMatchConfig
} from '../src/title';
import * as github from '@actions/github';
jest.mock('@actions/core');
jest.mock('@actions/github');
describe('getTitle', () => {
describe('when the pull requests title is requested', () => {
it('returns the title', () => {
const result = getTitle();
expect(result).toEqual('pr-title');
});
});
});
describe('checkAllTitle', () => {
beforeEach(() => {
github.context.payload.pull_request!.title = 'type(scope): description';
});
describe('when a single pattern is provided', () => {
describe('and the pattern matches the title', () => {
it('returns true', () => {
const result = checkAllTitle(['^type']);
expect(result).toBe(true);
});
});
describe('and the pattern does not match the title', () => {
it('returns false', () => {
const result = checkAllTitle(['^feature/']);
expect(result).toBe(false);
});
});
});
describe('when multiple patterns are provided', () => {
describe('and not all patterns matched', () => {
it('returns false', () => {
const result = checkAllTitle(['^type', '^test']);
expect(result).toBe(false);
});
});
describe('and all patterns match', () => {
it('returns true', () => {
const result = checkAllTitle(['^type', '^\\w+\\(scope\\):']);
expect(result).toBe(true);
});
});
describe('and no patterns match', () => {
it('returns false', () => {
const result = checkAllTitle(['^feature', 'test$']);
expect(result).toBe(false);
});
});
});
});
describe('checkAnyTitle', () => {
beforeEach(() => {
github.context.payload.pull_request!.title = 'type(scope): description';
});
describe('when a single pattern is provided', () => {
describe('and the pattern matches the title', () => {
it('returns true', () => {
const result = checkAnyTitle(['^type']);
expect(result).toBe(true);
});
});
describe('and the pattern does not match the title', () => {
it('returns false', () => {
const result = checkAnyTitle(['^test']);
expect(result).toBe(false);
});
});
});
describe('when multiple patterns are provided', () => {
describe('and at least one pattern matches', () => {
it('returns true', () => {
const result = checkAnyTitle(['^type', '^test']);
expect(result).toBe(true);
});
});
describe('and all patterns match', () => {
it('returns true', () => {
const result = checkAnyTitle(['^type', '^\\w+\\(scope\\):']);
expect(result).toBe(true);
});
});
describe('and no patterns match', () => {
it('returns false', () => {
const result = checkAllTitle(['^feature', 'test$']);
expect(result).toBe(false);
});
});
});
});
describe('toTitleMatchConfig', () => {
describe('when there are no title keys in the config', () => {
const config = {'changed-files': [{any: ['testing']}]};
it('returns an empty object', () => {
const result = toTitleMatchConfig(config);
expect(result).toEqual({});
});
});
describe('when the config contains a title option', () => {
const config = {title: ['testing']};
it('sets title in the matchConfig', () => {
const result = toTitleMatchConfig(config);
expect(result).toEqual<TitleMatchConfig>({
title: ['testing']
});
});
describe('and the matching option is a string', () => {
const stringConfig = {title: 'testing'};
it('sets title in the matchConfig', () => {
const result = toTitleMatchConfig(stringConfig);
expect(result).toEqual<TitleMatchConfig>({
title: ['testing']
});
});
});
});
});