-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelper.test.js
80 lines (62 loc) · 2.68 KB
/
helper.test.js
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
const sut = require('./helper.js');
const redmine_host = 'https://redmine.example.com';
describe('parse_redmine_issue', () => {
it('ssue parse single issue', async () => {
const body = 'https://redmine.example.com/issues/776';
const actual = await sut.parse_redmine_issues(body, redmine_host);
expect(actual).toEqual(expect.arrayContaining([776]));
});
it('parse nothing from body w/o URL', async () => {
const body = 'This is pull request body without redmine URL.';
const actual = await sut.parse_redmine_issues(body, redmine_host);
expect(actual).toHaveLength(0);
});
it('parse nothing from body with different URL', async () => {
const body = 'https://redmine.example.org/issues/776';
const actual = await sut.parse_redmine_issues(body, redmine_host);
expect(actual).toHaveLength(0);
});
it('parse issue with extra strings', async () => {
const body = 'issue https://redmine.example.com/issues/776 is here';
const actual = await sut.parse_redmine_issues(body, redmine_host);
expect(actual).toEqual(expect.arrayContaining([776]));
});
it('parse issues from multiple URL', async () => {
const body = '* https://redmine.example.com/issues/123\n* https://redmine.example.com/issues/456';
const actual = await sut.parse_redmine_issues(body, redmine_host);
expect(actual).toEqual(expect.arrayContaining([123, 456]));
});
it('parse issues containing quotation in body', async () => {
const body = `it's my issue: "https://redmine.example.com/issues/123"`;
const actual = await sut.parse_redmine_issues(body, redmine_host);
expect(actual).toEqual(expect.arrayContaining([123]));
});
});
describe('build_message', () => {
it('create message from title and action', async () => {
const prdata = {
"title": "my pull request title",
"html_url": "https://github.com/thaim/redmine-integration-action/pull/456"
};
const context = {
"payload": {
"action": "opened"
}
};
const actual = await sut.build_message(prdata, context);
expect(actual).toEqual("pull request [my pull request title](https://github.com/thaim/redmine-integration-action/pull/456) opened");
});
it('create message which contains quotation in title', async () => {
const prdata = {
"title": "it's my pull request title",
"html_url": "https://github.com/thaim/redmine-integration-action/pull/456"
};
const context = {
"payload": {
"action": "opened"
}
};
const actual = await sut.build_message(prdata, context);
expect(actual).toEqual("pull request [it's my pull request title](https://github.com/thaim/redmine-integration-action/pull/456) opened");
});
});