mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-14 20:41:15 +00:00
Added specs for when comment body is empty
This commit is contained in:
parent
2350aa6ad6
commit
286dc15e40
1 changed files with 83 additions and 46 deletions
|
|
@ -4,6 +4,13 @@ import {
|
|||
updateComment,
|
||||
deleteComment
|
||||
} from "../src/comment";
|
||||
|
||||
import * as core from '@actions/core';
|
||||
|
||||
jest.mock('@actions/core', () => ({
|
||||
warning: jest.fn()
|
||||
}));
|
||||
|
||||
const repo = {};
|
||||
it("findPreviousComment", async () => {
|
||||
const comment = {
|
||||
|
|
@ -55,12 +62,19 @@ it("findPreviousComment", async () => {
|
|||
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(headerFirstComment)
|
||||
expect(octokit.issues.listComments).toBeCalledWith({ issue_number: 123 });
|
||||
});
|
||||
it("updateComment", async () => {
|
||||
const octokit = {
|
||||
|
||||
describe("updateComment", () => {
|
||||
let octokit;
|
||||
|
||||
beforeEach(() => {
|
||||
octokit = {
|
||||
issues: {
|
||||
updateComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
it("with comment body", async() => {
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, "hello there", "")
|
||||
).toBeUndefined();
|
||||
|
|
@ -75,7 +89,6 @@ it("updateComment", async () => {
|
|||
comment_id: 456,
|
||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||
});
|
||||
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, "hello there", "TypeA", "hello there\n<!-- Sticky Pull Request CommentTypeA -->")
|
||||
).toBeUndefined();
|
||||
|
|
@ -83,13 +96,29 @@ it("updateComment", async () => {
|
|||
comment_id: 456,
|
||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there"
|
||||
});
|
||||
});
|
||||
|
||||
it("without comment body and previousbody", async() => {
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, "", "")
|
||||
).toBeUndefined();
|
||||
expect(octokit.issues.updateComment).not.toBeCalled();
|
||||
expect(core.warning).toBeCalledWith('Comment body cannot be blank');
|
||||
})
|
||||
});
|
||||
it("createComment", async () => {
|
||||
const octokit = {
|
||||
|
||||
describe("createComment", () => {
|
||||
let octokit;
|
||||
|
||||
beforeEach(() => {
|
||||
octokit = {
|
||||
issues: {
|
||||
createComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
it("with comment body or previousBody", async () => {
|
||||
expect(
|
||||
await createComment(octokit, repo, 456, "hello there", "")
|
||||
).toBeUndefined();
|
||||
|
|
@ -104,6 +133,14 @@ it("createComment", async () => {
|
|||
issue_number: 456,
|
||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||
});
|
||||
})
|
||||
it("without comment body and previousBody", async () => {
|
||||
expect(
|
||||
await createComment(octokit, repo, 456, "", "")
|
||||
).toBeUndefined();
|
||||
expect(octokit.issues.createComment).not.toBeCalled();
|
||||
expect(core.warning).toBeCalledWith('Comment body cannot be blank');
|
||||
})
|
||||
});
|
||||
|
||||
it("deleteComment", async () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue