Skip to content

Commit

Permalink
Merge pull request ubiquity-os#51 from ubiquity/default-config-bug
Browse files Browse the repository at this point in the history
Default config bug
  • Loading branch information
0x4007 authored Jun 6, 2024
2 parents b4ad844 + ddedba0 commit b433000
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/github/types/plugin-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const pluginChainSchema = T.Array(
type: T.Union([T.Literal("github")], { default: "github" }),
with: T.Record(T.String(), T.Unknown(), { default: {} }),
}),
{ minItems: 1 }
{ minItems: 1, default: [] }
);

export type PluginChain = StaticDecode<typeof pluginChainSchema>;
Expand Down
40 changes: 40 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,46 @@ describe("Worker tests", () => {
} as unknown as GitHubContext);
expect(cfg).toBeTruthy();
});
it("Should fill the config with defaults", async () => {
const cfg = await getConfig({
key: issueOpened,
name: issueOpened,
id: "",
payload: {
repository: {
owner: { login: "ubiquity" },
name: "ubiquibot-kernel",
},
} as unknown as GitHubContext<"issues.closed">["payload"],
octokit: {
rest: {
repos: {
getContent() {
return {
data: `
plugins:
issue_comment.created:
- name: "Run on comment created"
uses:
- id: plugin-A
plugin: https://plugin-a.internal
`,
};
},
},
},
},
eventHandler: {} as GitHubEventHandler,
} as unknown as GitHubContext);
expect(cfg).toBeTruthy();
const pluginChain = cfg.plugins["issue_comment.created"];
expect(pluginChain.length).toBe(1);
expect(pluginChain[0].uses.length).toBe(1);
expect(pluginChain[0].skipBotEvents).toBeTrue();
expect(pluginChain[0].uses[0].id).toBe("plugin-A");
expect(pluginChain[0].uses[0].plugin).toBe("https://plugin-a.internal");
expect(pluginChain[0].uses[0].with).toEqual({});
});
it("Should merge the configuration when found", async () => {
const cfg = await getConfig({
key: issueOpened,
Expand Down

0 comments on commit b433000

Please sign in to comment.