Skip to content

Commit e103a51

Browse files
committed
Fix test for updating a comment
1 parent 74f796b commit e103a51

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

index.test.js

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ describe("changeset-bot", () => {
3939
}),
4040
});
4141

42-
4342
app = changesetBot.default(probot)
4443

4544
// just return a test token
4645
app.app = () => "test.ts";
4746
});
4847

49-
it("should add a comment when there is no comment", async () => {
48+
beforeEach(() => {
5049
nock("https://raw.githubusercontent.com")
5150
.get("/changesets/bot/test/package.json")
5251
.reply(200, {})
@@ -65,22 +64,19 @@ describe("changeset-bot", () => {
6564
.post("/app/installations/2462428/access_tokens")
6665
.reply(200, [])
6766

68-
nock("https://api.github.com")
69-
.get("/repos/pyu/testing-things/issues/1/comments")
70-
.reply(200, []);
67+
})
7168

69+
it("should add a comment when there is no comment", async () => {
7270
nock("https://api.github.com")
7371
.get("/repos/changesets/bot/pulls/2/files")
7472
.reply(200, [
7573
{ filename: ".changeset/something/changes.md", status: "added" }
7674
]);
7775

78-
nock("https://api.github.com")
79-
.get("/repos/pyu/testing-things/pulls/1/commits")
80-
.reply(200, [{ sha: "ABCDE" }]);
81-
76+
// checks and creates a comment
8277
nock("https://api.github.com")
8378
.post("/repos/changesets/bot/issues/2/comments", body => {
79+
expect(body.body).toContain("Changeset detected")
8480
expect(body.comment_id).toBeUndefined()
8581
return true;
8682
})
@@ -93,33 +89,31 @@ describe("changeset-bot", () => {
9389
});
9490

9591
it("should update a comment when there is a comment", async () => {
96-
nock("https://api.github.com")
97-
.get("/repos/pyu/testing-things/issues/1/comments")
98-
.reply(200, [
99-
{
100-
id: 7,
101-
user: {
102-
login: "changeset-bot[bot]"
103-
}
104-
}
105-
]);
92+
const commentId = 123
10693

10794
nock("https://api.github.com")
108-
.get("/repos/pyu/testing-things/pulls/1/files")
109-
.reply(200, [
110-
{ filename: ".changeset/something/changes.md", status: "added" }
111-
]);
95+
.get("/repos/changesets/bot/pulls/2/files")
96+
.reply(200, [
97+
{ filename: ".changeset/something/changes.md", status: "added" }
98+
]);
11299

100+
// get comments for an issue
113101
nock("https://api.github.com")
114-
.get("/repos/pyu/testing-things/pulls/1/commits")
115-
.reply(200, [{ sha: "ABCDE" }]);
102+
.get("/repos/changesets/bot/issues/2/comments")
103+
.reply(200, [{
104+
id: commentId,
105+
user: {
106+
login: "changeset-bot[bot]"
107+
}
108+
}]);
116109

110+
// update comments for an issue
117111
nock("https://api.github.com")
118-
.patch("/repos/pyu/testing-things/issues/comments/7", body => {
119-
expect(body.number).toBe(1);
120-
return true;
121-
})
122-
.reply(200);
112+
.patch(`/repos/changesets/bot/issues/comments/${commentId}`, body => {
113+
expect(body.body).toContain("Changeset detected")
114+
return true;
115+
})
116+
.reply(200);
123117

124118
await probot.receive({
125119
name: "pull_request",

index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ export default (app: Probot) => {
210210

211211
let prComment = {
212212
...repo,
213-
issue_number: number,
214213
body:
215214
(hasChangeset
216215
? getApproveMessage(latestCommitSha, addChangesetUrl, releasePlan)
@@ -227,7 +226,10 @@ export default (app: Probot) => {
227226
comment_id: commentId,
228227
});
229228
}
230-
return context.octokit.issues.createComment(prComment);
229+
return context.octokit.issues.createComment({
230+
...prComment,
231+
issue_number: number,
232+
});
231233
} catch (err) {
232234
console.error(err);
233235
throw err;

0 commit comments

Comments
 (0)