-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.js
105 lines (93 loc) · 3.14 KB
/
index.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
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
"use strict";
const { addToTriageProject } = require("../../../src/plugins/index");
const nock = require("nock");
const { Application } = require("probot");
const { NEEDS_TRIAGE_COLUMN_ID } = require("../../../src/constants");
const GitHubApi = require("@octokit/rest");
describe("add-to-triage-project", () => {
let bot = null;
beforeAll(() => {
bot = new Application({
id: "test",
cert: "test",
cache: {
wrap: () => Promise.resolve({ data: { token: "test" } })
}
});
bot.auth = () => new GitHubApi();
addToTriageProject(bot);
});
afterEach(() => {
nock.cleanAll();
});
describe("issue opened", () => {
test("Adds the issue to the project", async () => {
const addIssueToTriageProject = nock("https://api.github.com")
.post(`/projects/columns/${NEEDS_TRIAGE_COLUMN_ID}/cards`, body => {
expect(body).toEqual({
content_id: 1234,
content_type: "Issue"
});
return true;
})
.reply(200);
await bot.receive({
name: "issues",
payload: {
action: "opened",
installation: {
id: 1
},
issue: {
labels: [],
number: 1,
id: 1234
},
repository: {
name: "repo-test",
owner: {
login: "test"
}
}
}
});
expect(addIssueToTriageProject.isDone()).toBeTruthy();
});
test("doesn't add the issue to the project when 'triage:no' label is present", async () => {
const addIssueToTriageProject = nock("https://api.github.com")
.post(`/projects/columns/${NEEDS_TRIAGE_COLUMN_ID}/cards`, body => {
expect(body).toEqual({
content_id: 1234,
content_type: "Issue"
});
return true;
})
.reply(200);
await bot.receive({
name: "issues",
payload: {
action: "opened",
installation: {
id: 1
},
issue: {
labels: [
{
name: "triage:no"
}
],
number: 1,
id: 1234
},
repository: {
name: "repo-test",
owner: {
login: "test"
}
}
}
});
expect(addIssueToTriageProject.isDone()).toBeFalsy();
});
});
});