Skip to content

Commit

Permalink
feat: test for skipBotEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Sep 10, 2024
1 parent d292f5a commit 128e93e
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions tests/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });

Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -92,7 +94,7 @@ describe("Configuration tests", () => {
},
},
],
skipBotEvents: true,
skipBotEvents: false,
});
});
it("Should retrieve the configuration manifest from the proper branch if specified", async () => {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit 128e93e

Please sign in to comment.