mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-14 20:41:15 +00:00
test: comment
This commit is contained in:
parent
fd286f3230
commit
eba69144ce
2 changed files with 55 additions and 2 deletions
55
__tests__/comment.test.ts
Normal file
55
__tests__/comment.test.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import {
|
||||
findPreviousComment,
|
||||
createComment,
|
||||
updateComment
|
||||
} from "../src/comment";
|
||||
const repo = {};
|
||||
const body = "some message";
|
||||
it("findPreviousComment", async () => {
|
||||
const comment = {
|
||||
user: {
|
||||
login: "github-actions[bot]"
|
||||
}
|
||||
};
|
||||
const otherComment = {
|
||||
user: {
|
||||
login: "some-user"
|
||||
}
|
||||
};
|
||||
const octokit = {
|
||||
issues: {
|
||||
listComments: jest.fn(() =>
|
||||
Promise.resolve({
|
||||
data: [otherComment, comment]
|
||||
})
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
expect(await findPreviousComment(octokit, repo, 123)).toBe(comment);
|
||||
expect(octokit.issues.listComments).toBeCalledWith({ issue_number: 123 });
|
||||
});
|
||||
it("updateComment", async () => {
|
||||
const octokit = {
|
||||
issues: {
|
||||
updateComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
};
|
||||
expect(await updateComment(octokit, repo, 456, body)).toBeUndefined();
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
body
|
||||
});
|
||||
});
|
||||
it("createComment", async () => {
|
||||
const octokit = {
|
||||
issues: {
|
||||
createComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
};
|
||||
expect(await createComment(octokit, repo, 456, body)).toBeUndefined();
|
||||
expect(octokit.issues.createComment).toBeCalledWith({
|
||||
issue_number: 456,
|
||||
body
|
||||
});
|
||||
});
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
test("create a comment when no comment", async () => {});
|
||||
test("update a comment when comment is exists", async () => {});
|
||||
Loading…
Reference in a new issue