Skip to content

Commit

Permalink
test: added tests for comment reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jan 6, 2025
1 parent f56e5e4 commit 76cca90
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir", "typebox"],
"words": ["dataurl", "devpool", "outdir", "servedir", "typebox", "gentlementlegen"],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"]
Expand Down
59 changes: 59 additions & 0 deletions tests/comment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { describe, expect, it, jest } from "@jest/globals";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { Context, postComment } from "../src";

describe("Post comment tests", () => {
it("Should reuse a message if the reuse option is true", async () => {
const logger = new Logs("debug");
const createComment = jest.fn(() => ({
data: {
id: 1234,
},
}));
const updateComment = jest.fn(() => ({
data: {
id: 1234,
},
}));
jest.unstable_mockModule("@octokit/core", () => ({
Octokit: jest.fn(() => ({
rest: {
issues: {
createComment,
updateComment,
},
},
})),
}));
const { Octokit } = await import("@octokit/core");
const ctx = {
payload: {
issue: {
number: 1,
},
repository: {
owner: {
login: "ubiquity-os",
},
name: "plugin-sdk",
},
},
logger,
octokit: new Octokit(),
} as unknown as Context;
await postComment(ctx, logger.ok("test"), { updateComment: true });
await postComment(ctx, logger.ok("test 2"), { updateComment: true });
expect(createComment).toHaveBeenCalledWith({
owner: "ubiquity-os",
repo: "plugin-sdk",
issue_number: 1,
body: expect.anything(),
});
expect(updateComment).toHaveBeenCalledWith({
owner: "ubiquity-os",
repo: "plugin-sdk",
comment_id: 1234,
body: expect.anything(),
});
});
});

0 comments on commit 76cca90

Please sign in to comment.