-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.test.js
171 lines (136 loc) · 4.99 KB
/
index.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const nock = require("nock");
const { Probot } = require("probot");
const outdent = require("outdent");
const changesetBot = require(".");
const pullRequestOpen = require("./test/fixtures/pull_request.opened");
const pullRequestSynchronize = require("./test/fixtures/pull_request.synchronize");
const releasePullRequestOpen = require("./test/fixtures/release_pull_request.opened");
nock.disableNetConnect();
/*
Oh god none of these tests work - we should really do something about having this tested
*/
describe.skip("changeset-bot", () => {
let probot;
beforeEach(() => {
probot = new Probot({});
const app = probot.load(changesetBot);
// just return a test token
app.app = () => "test.ts";
});
it("should add a comment when there is no comment", async () => {
nock("https://api.github.com")
.get("/repos/pyu/testing-things/issues/1/comments")
.reply(200, []);
nock("https://api.github.com")
.get("/repos/pyu/testing-things/pulls/1/files")
.reply(200, [
{ filename: ".changeset/something/changes.md", status: "added" }
]);
nock("https://api.github.com")
.get("/repos/pyu/testing-things/pulls/1/commits")
.reply(200, [{ sha: "ABCDE" }]);
nock("https://api.github.com")
.post("/repos/pyu/testing-things/issues/1/comments", body => {
expect(body.comment_id).toBeNull();
return true;
})
.reply(200);
await probot.receive({
name: "pull_request",
payload: pullRequestOpen
});
});
it("should update a comment when there is a comment", async () => {
nock("https://api.github.com")
.get("/repos/pyu/testing-things/issues/1/comments")
.reply(200, [
{
id: 7,
user: {
login: "changeset-bot[bot]"
}
}
]);
nock("https://api.github.com")
.get("/repos/pyu/testing-things/pulls/1/files")
.reply(200, [
{ filename: ".changeset/something/changes.md", status: "added" }
]);
nock("https://api.github.com")
.get("/repos/pyu/testing-things/pulls/1/commits")
.reply(200, [{ sha: "ABCDE" }]);
nock("https://api.github.com")
.patch("/repos/pyu/testing-things/issues/comments/7", body => {
expect(body.number).toBe(1);
return true;
})
.reply(200);
await probot.receive({
name: "pull_request",
payload: pullRequestSynchronize
});
});
it("should show correct message if there is a changeset", async () => {
nock("https://api.github.com")
.get("/repos/pyu/testing-things/issues/1/comments")
.reply(200, []);
nock("https://api.github.com")
.get("/repos/pyu/testing-things/pulls/1/files")
.reply(200, [
{ filename: ".changeset/something/changes.md", status: "added" }
]);
nock("https://api.github.com")
.get("/repos/pyu/testing-things/pulls/1/commits")
.reply(200, [{ sha: "ABCDE" }]);
nock("https://api.github.com")
.post("/repos/pyu/testing-things/issues/1/comments", ({ body }) => {
expect(body).toEqual(outdent`
### 🦋 Changeset is good to go
Latest commit: ABCDE
**We got this.**
Not sure what this means? [Click here to learn what changesets are](https://github.com/Noviny/changesets/blob/master/docs/adding-a-changeset.md).`);
return true;
})
.reply(200);
await probot.receive({
name: "pull_request",
payload: pullRequestOpen
});
});
it("should show correct message if there is no changeset", async () => {
nock("https://api.github.com")
.get("/repos/pyu/testing-things/issues/1/comments")
.reply(200, []);
nock("https://api.github.com")
.get("/repos/pyu/testing-things/pulls/1/files")
.reply(200, [{ filename: "index.js", status: "added" }]);
nock("https://api.github.com")
.get("/repos/pyu/testing-things/pulls/1/commits")
.reply(200, [{ sha: "ABCDE" }]);
nock("https://api.github.com")
.post("/repos/pyu/testing-things/issues/1/comments", ({ body }) => {
expect(body).toEqual(outdent`
### 💥 No Changeset
Latest commit: ABCDE
Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂
**If these changes should be published to npm, you need to add a changeset.**
[Click here to learn what changesets are, and how to add one](https://github.com/Noviny/changesets/blob/master/docs/adding-a-changeset.md).`);
return true;
})
.reply(200);
await probot.receive({
name: "pull_request",
payload: pullRequestOpen
});
});
it("shouldn't add a comment to a release pull request", async () => {
nock("https://api.github.com").reply(() => {
// shouldn't reach this, but if it does - let it fail
expect(true).toBe(false);
});
await probot.receive({
name: "pull_request",
payload: releasePullRequestOpen
});
});
});