From 76cca901c5ac14a5161918ce7d7b7eb1c32c01e9 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Mon, 6 Jan 2025 10:23:19 +0900 Subject: [PATCH] test: added tests for comment reuse --- .cspell.json | 2 +- tests/comment.test.ts | 59 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/comment.test.ts diff --git a/.cspell.json b/.cspell.json index ae85a2a..407d2d2 100644 --- a/.cspell.json +++ b/.cspell.json @@ -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}"] diff --git a/tests/comment.test.ts b/tests/comment.test.ts new file mode 100644 index 0000000..6ebb5fd --- /dev/null +++ b/tests/comment.test.ts @@ -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(), + }); + }); +});