Skip to content

Commit

Permalink
Added validation to not have duplicated rule names
Browse files Browse the repository at this point in the history
This closes #32
  • Loading branch information
Bullrich committed Aug 8, 2023
1 parent b1c2c41 commit dd909ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/file/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const ruleSchema = Joi.object<Rule & { type: string }>().keys({
* Remember to evaluate the rules with their custom rules
*/
export const generalSchema = Joi.object<ConfigurationFile>().keys({
rules: Joi.array<ConfigurationFile["rules"]>().items(ruleSchema).required(),
rules: Joi.array<ConfigurationFile["rules"]>().items(ruleSchema).unique("name").required(),
preventReviewRequests: Joi.object().keys(reviewersObj).optional().xor("users", "teams"),
});

Expand Down
21 changes: 21 additions & 0 deletions src/test/runner/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ describe("Config Parsing", () => {
'Configuration file is invalid: "rules[0].type" must be one of [basic, debug]',
);
});

test("should fail with duplicated rule name", async () => {
api.getConfigFile.mockResolvedValue(`
rules:
- name: Default review
condition:
include:
- '.*'
type: basic
teams:
- team-example
- name: Default review
condition:
include:
- 'src'
type: basic
teams:
- team-2
`);
await expect(runner.getConfigFile("")).rejects.toThrowError("contains a duplicate value");
});
});

describe("regular expressions validator", () => {
Expand Down

0 comments on commit dd909ab

Please sign in to comment.