Skip to content

Commit

Permalink
added tests for the comment class
Browse files Browse the repository at this point in the history
  • Loading branch information
Bullrich committed Sep 28, 2023
1 parent 076636b commit 9394fcc
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@types/jest": "^29.5.5",
"@vercel/ncc": "^0.38.0",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.5",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
}
Expand Down
55 changes: 55 additions & 0 deletions src/test/comments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { DeepMockProxy, mock, mockDeep, MockProxy } from "jest-mock-extended";

import { CommentsApi } from "../github/comments";
import { ActionLogger, GitHubClient } from "../github/types";

describe("Comments", () => {
let comments: CommentsApi;
let api: DeepMockProxy<GitHubClient>;
let logger: MockProxy<ActionLogger>;
const repo = { repo: "example", owner: "me", number: 123 };
beforeEach(() => {
api = mockDeep<GitHubClient>();
logger = mock<ActionLogger>();
comments = new CommentsApi(api, logger, repo);
});

describe("Comment action", () => {
test("Should comment", async () => {
await comments.comment("Hello");
expect(api.rest.issues.createComment).toHaveBeenCalledWith({
body: "Hello",
...repo,
issue_number: repo.number,
});
});

test("Should log when commenting", async () => {
await comments.comment("Log this");
expect(logger.info).toHaveBeenCalledWith("Commenting: Log this");
});

test("Should not comment on silent mode", async () => {
comments = new CommentsApi(api, logger, repo, true);
await comments.comment("Example");
expect(api.rest.issues.createComment).not.toHaveBeenCalled();
});

test("Should log while in silent mode", async () => {
comments = new CommentsApi(api, logger, repo, true);
await comments.comment("Bye");
expect(logger.info).toHaveBeenCalledWith("Commenting: Bye");
});

test("Should override silent mode", async () => {
comments = new CommentsApi(api, logger, repo, true);
await comments.comment("Overrider", true);
expect(api.rest.issues.createComment).toHaveBeenCalledWith({
body: "Overrider",
...repo,
issue_number: repo.number,
});
});
});
});
3 changes: 0 additions & 3 deletions src/test/index.ts

This file was deleted.

12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,13 @@ jest-message-util@^29.7.0:
slash "^3.0.0"
stack-utils "^2.0.3"

jest-mock-extended@^3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/jest-mock-extended/-/jest-mock-extended-3.0.5.tgz#ebf208e363f4f1db603b81fb005c4055b7c1c8b7"
integrity sha512-/eHdaNPUAXe7f65gHH5urc8SbRVWjYxBqmCgax2uqOBJy8UUcCBMN1upj1eZ8y/i+IqpyEm4Kq0VKss/GCCTdw==
dependencies:
ts-essentials "^7.0.3"

jest-mock@^29.7.0:
version "29.7.0"
resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-29.7.0.tgz#4e836cf60e99c6fcfabe9f99d017f3fdd50a6347"
Expand Down Expand Up @@ -3781,6 +3788,11 @@ tr46@~0.0.3:
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

ts-essentials@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-7.0.3.tgz#686fd155a02133eedcc5362dc8b5056cde3e5a38"
integrity sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==

ts-jest@^29.1.1:
version "29.1.1"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.1.tgz#f58fe62c63caf7bfcc5cc6472082f79180f0815b"
Expand Down

0 comments on commit 9394fcc

Please sign in to comment.