From 128e93efc9a28533834d009d582f62894a2a4927 Mon Sep 17 00:00:00 2001 From: whilefoo Date: Tue, 10 Sep 2024 13:03:04 +0200 Subject: [PATCH] feat: test for skipBotEvents --- tests/configuration.test.ts | 69 +++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/tests/configuration.test.ts b/tests/configuration.test.ts index 6d2334e..a5eaeed 100644 --- a/tests/configuration.test.ts +++ b/tests/configuration.test.ts @@ -7,6 +7,7 @@ import { GitHubContext } from "../src/github/github-context"; import { GitHubEventHandler } from "../src/github/github-event-handler"; import { getManifest } from "../src/github/utils/plugins"; import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"; +import { shouldSkipPlugin } from "../src/github/handlers"; config({ path: ".dev.vars" }); @@ -44,7 +45,8 @@ describe("Configuration tests", () => { - uses: - plugin: ubiquity/user-activity-watcher:compute.yml@fork/pull/1 with: - settings1: 'enabled'`; + settings1: 'enabled' + skipBotEvents: false`; } if (args.mediaType === undefined || args.mediaType?.format === "base64") { @@ -92,7 +94,7 @@ describe("Configuration tests", () => { }, }, ], - skipBotEvents: true, + skipBotEvents: false, }); }); it("Should retrieve the configuration manifest from the proper branch if specified", async () => { @@ -160,4 +162,67 @@ describe("Configuration tests", () => { ); expect(manifest).toEqual(content["withoutRef"]); }); + it("should not skip bot event if skipBotEvents is set to false", async () => { + function getContent(args: RestEndpointMethodTypes["repos"]["getContent"]["parameters"]) { + let data: string; + if (args.path === "manifest.json") { + data = ` + { + "name": "plugin", + "commands": { + "command": { + "description": "description", + "ubiquity:example": "example" + } + } + } + `; + } else { + data = ` + plugins: + - uses: + - plugin: ubiquity/test-plugin + with: + settings1: 'enabled' + skipBotEvents: false`; + } + + if (args.mediaType === undefined || args.mediaType?.format === "base64") { + return { + data: { + content: Buffer.from(data).toString("base64"), + }, + }; + } else if (args.mediaType?.format === "raw") { + return { data }; + } + } + + const context = { + key: issueOpened, + name: issueOpened, + id: "", + payload: { + repository: { + owner: { login: "ubiquity" }, + name: "conversation-rewards", + }, + sender: { + type: "Bot", + }, + } as unknown as GitHubContext<"issues.closed">["payload"], + octokit: { + rest: { + repos: { + getContent, + }, + }, + }, + eventHandler: {} as GitHubEventHandler, + } as unknown as GitHubContext; + + const cfg = await getConfig(context); + expect(cfg.plugins[0].skipBotEvents).toEqual(false); + await expect(shouldSkipPlugin(context, cfg.plugins[0])).resolves.toEqual(false); + }); });