test: find & write with comment header

This commit is contained in:
marocchino 2019-11-23 10:44:03 +09:00
parent 5a3fa9621f
commit 0c015d9eea
No known key found for this signature in database
GPG key ID: AFF521DBDB122570

View file

@ -4,17 +4,18 @@ import {
updateComment updateComment
} from "../src/comment"; } from "../src/comment";
const repo = {}; const repo = {};
const body = "some message";
it("findPreviousComment", async () => { it("findPreviousComment", async () => {
const comment = { const comment = {
user: { user: {
login: "github-actions[bot]" login: "github-actions[bot]"
} },
body: "<!-- Sticky Pull Request Comment -->\nprevious message"
}; };
const otherComment = { const otherComment = {
user: { user: {
login: "some-user" login: "some-user"
} },
body: "lgtm"
}; };
const octokit = { const octokit = {
issues: { issues: {
@ -35,10 +36,12 @@ it("updateComment", async () => {
updateComment: jest.fn(() => Promise.resolve()) updateComment: jest.fn(() => Promise.resolve())
} }
}; };
expect(await updateComment(octokit, repo, 456, body)).toBeUndefined(); expect(
await updateComment(octokit, repo, 456, "hello there")
).toBeUndefined();
expect(octokit.issues.updateComment).toBeCalledWith({ expect(octokit.issues.updateComment).toBeCalledWith({
comment_id: 456, comment_id: 456,
body body: "<!-- Sticky Pull Request Comment -->\nhello there"
}); });
}); });
it("createComment", async () => { it("createComment", async () => {
@ -47,9 +50,11 @@ it("createComment", async () => {
createComment: jest.fn(() => Promise.resolve()) createComment: jest.fn(() => Promise.resolve())
} }
}; };
expect(await createComment(octokit, repo, 456, body)).toBeUndefined(); expect(
await createComment(octokit, repo, 456, "hello there")
).toBeUndefined();
expect(octokit.issues.createComment).toBeCalledWith({ expect(octokit.issues.createComment).toBeCalledWith({
issue_number: 456, issue_number: 456,
body body: "<!-- Sticky Pull Request Comment -->\nhello there"
}); });
}); });