Added specs for when comment body is empty

This commit is contained in:
Sebass van Boxel 2020-11-04 22:21:20 +01:00
parent 2350aa6ad6
commit 286dc15e40
No known key found for this signature in database
GPG key ID: A1E93D1FBDF515B7

View file

@ -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();
@ -84,12 +97,28 @@ it("updateComment", async () => {
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there"
});
});
it("createComment", async () => {
const octokit = {
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');
})
});
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 () => {