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, updateComment,
deleteComment deleteComment
} from "../src/comment"; } from "../src/comment";
import * as core from '@actions/core';
jest.mock('@actions/core', () => ({
warning: jest.fn()
}));
const repo = {}; const repo = {};
it("findPreviousComment", async () => { it("findPreviousComment", async () => {
const comment = { const comment = {
@ -55,55 +62,85 @@ it("findPreviousComment", async () => {
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(headerFirstComment) expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(headerFirstComment)
expect(octokit.issues.listComments).toBeCalledWith({ issue_number: 123 }); expect(octokit.issues.listComments).toBeCalledWith({ issue_number: 123 });
}); });
it("updateComment", async () => {
const octokit = { describe("updateComment", () => {
issues: { let octokit;
updateComment: jest.fn(() => Promise.resolve())
} beforeEach(() => {
}; octokit = {
expect( issues: {
await updateComment(octokit, repo, 456, "hello there", "") updateComment: jest.fn(() => Promise.resolve())
).toBeUndefined(); }
expect(octokit.issues.updateComment).toBeCalledWith({ };
comment_id: 456, })
body: "hello there\n<!-- Sticky Pull Request Comment -->"
}); it("with comment body", async() => {
expect( expect(
await updateComment(octokit, repo, 456, "hello there", "TypeA") await updateComment(octokit, repo, 456, "hello there", "")
).toBeUndefined(); ).toBeUndefined();
expect(octokit.issues.updateComment).toBeCalledWith({ expect(octokit.issues.updateComment).toBeCalledWith({
comment_id: 456, comment_id: 456,
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->" body: "hello there\n<!-- Sticky Pull Request Comment -->"
});
expect(
await updateComment(octokit, repo, 456, "hello there", "TypeA")
).toBeUndefined();
expect(octokit.issues.updateComment).toBeCalledWith({
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();
expect(octokit.issues.updateComment).toBeCalledWith({
comment_id: 456,
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there"
});
}); });
expect( it("without comment body and previousbody", async() => {
await updateComment(octokit, repo, 456, "hello there", "TypeA", "hello there\n<!-- Sticky Pull Request CommentTypeA -->") expect(
).toBeUndefined(); await updateComment(octokit, repo, 456, "", "")
expect(octokit.issues.updateComment).toBeCalledWith({ ).toBeUndefined();
comment_id: 456, expect(octokit.issues.updateComment).not.toBeCalled();
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there" expect(core.warning).toBeCalledWith('Comment body cannot be blank');
}); })
}); });
it("createComment", async () => {
const octokit = { describe("createComment", () => {
issues: { let octokit;
createComment: jest.fn(() => Promise.resolve())
} beforeEach(() => {
}; octokit = {
expect( issues: {
await createComment(octokit, repo, 456, "hello there", "") createComment: jest.fn(() => Promise.resolve())
).toBeUndefined(); }
expect(octokit.issues.createComment).toBeCalledWith({ };
issue_number: 456, })
body: "hello there\n<!-- Sticky Pull Request Comment -->"
}); it("with comment body or previousBody", async () => {
expect( expect(
await createComment(octokit, repo, 456, "hello there", "TypeA") await createComment(octokit, repo, 456, "hello there", "")
).toBeUndefined(); ).toBeUndefined();
expect(octokit.issues.createComment).toBeCalledWith({ expect(octokit.issues.createComment).toBeCalledWith({
issue_number: 456, issue_number: 456,
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->" body: "hello there\n<!-- Sticky Pull Request Comment -->"
}); });
expect(
await createComment(octokit, repo, 456, "hello there", "TypeA")
).toBeUndefined();
expect(octokit.issues.createComment).toBeCalledWith({
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 () => { it("deleteComment", async () => {