Skip to content

Commit

Permalink
fix: added tests related to help command
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jul 10, 2024
1 parent 83e6e14 commit bfa8fe8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/github/handlers/issue-comment-created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function fetchActionManifest(context: GitHubContext<"issue_comment.created
return JSON.parse(content);
}
} catch (e) {
console.warn(`Could not find a manifest for ${owner}/${repo}`);
console.warn(`Could not find a manifest for ${owner}/${repo}: ${e}`);
}
return null;
}
Expand All @@ -75,7 +75,7 @@ async function fetchWorkerManifest(url: string): Promise<Manifest | null> {
const result = await fetch(manifestUrl);
return await result.json();
} catch (e) {
console.warn(`Could not find a manifest for ${manifestUrl}`);
console.warn(`Could not find a manifest for ${manifestUrl}: ${e}`);
}
return null;
}
51 changes: 46 additions & 5 deletions tests/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
import { afterAll, afterEach, beforeAll, describe, expect, it, mock, spyOn } from "bun:test";
import { afterAll, afterEach, beforeAll, describe, expect, it, mock, spyOn, beforeEach } from "bun:test";
import { config } from "dotenv";
import { http, HttpResponse } from "msw";
import { GitHubContext } from "../src/github/github-context";
import { GitHubEventHandler } from "../src/github/github-event-handler";
import issueCommentCreated from "../src/github/handlers/issue-comment-created";
Expand All @@ -24,6 +25,26 @@ afterAll(() => {
});

describe("Event related tests", () => {
beforeEach(() => {
server.use(
http.get("https://plugin-a.internal/manifest.json", () =>
HttpResponse.json({
commands: [
{
command: "/foo",
description: "foo command",
example: "/foo bar",
},
{
command: "/bar",
description: "bar command",
example: "/bar foo",
},
],
})
)
);
});
it("Should post the help menu when /help command is invoked", async () => {
const issues = {
createComment(params?: RestEndpointMethodTypes["issues"]["createComment"]["parameters"]) {
Expand All @@ -44,17 +65,37 @@ describe("Event related tests", () => {
plugins:
issue_comment.created:
- name: "Run on comment created"
description: "Plugin A"
example: /command [foo | bar]
command: /command
uses:
- id: plugin-A
plugin: https://plugin-a.internal
- name: "Some Action plugin"
uses:
- id: plugin-B
plugin: ubiquibot/plugin-b
`,
};
},
},
},
repos: {
getContent() {
return {
data: {
content: btoa(
JSON.stringify({
commands: [
{
command: "/action",
description: "action",
example: "/action",
},
],
})
),
},
};
},
},
},
eventHandler: {} as GitHubEventHandler,
payload: {
Expand All @@ -74,7 +115,7 @@ describe("Event related tests", () => {
{
body:
"### Available Commands\n\n\n| Command | Description | Example |\n|---|---|---|\n| `/help` | List" +
" all available commands. | `/help` |\n| `/command` | Plugin A | `/command [foo \\| bar]` |",
" all available commands. | `/help` |\n| `/action` | action | `/action` |\n| `/bar` | bar command | `/bar foo` |\n| `/foo` | foo command | `/foo bar` |",
issue_number: 1,
owner: "ubiquity",
repo: "ubiquibot-kernel",
Expand Down

0 comments on commit bfa8fe8

Please sign in to comment.