forked from paritytech/review-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created object for basic rule. First step towards paritytech#9 By using Types in typescript we can differ what is the type of rule easily. I also added checks to Joi to ensure that the rule has everything required before individually validating it. Added tests to evaluate the process thoroughly.
- Loading branch information
Showing
5 changed files
with
221 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
import { mock, MockProxy } from "jest-mock-extended"; | ||
|
||
import { BasicRule } from "../../file/types"; | ||
import { PullRequestApi } from "../../github/pullRequest"; | ||
import { ActionRunner } from "../../runner"; | ||
import { TestLogger } from "../logger"; | ||
|
||
describe("Basic rule parsing", () => { | ||
let api: MockProxy<PullRequestApi>; | ||
let runner: ActionRunner; | ||
let logger: TestLogger; | ||
beforeEach(() => { | ||
logger = new TestLogger(); | ||
api = mock<PullRequestApi>(); | ||
runner = new ActionRunner(api, logger); | ||
}); | ||
test("should get minimal config", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: basic | ||
teams: | ||
- team-example | ||
`); | ||
const config = await runner.getConfigFile(""); | ||
expect(config.rules[0].name).toEqual("Test review"); | ||
expect(config.rules[0].type).toEqual("basic"); | ||
}); | ||
|
||
test("should require teams", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: basic | ||
teams: | ||
- team-example | ||
`); | ||
const config = await runner.getConfigFile(""); | ||
const rule = config.rules[0] as BasicRule; | ||
expect(rule.teams).toContainEqual("team-example"); | ||
expect(rule.users).toBeUndefined(); | ||
}); | ||
test("should require users", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: basic | ||
users: | ||
- user-example | ||
`); | ||
const config = await runner.getConfigFile(""); | ||
const rule = config.rules[0] as BasicRule; | ||
expect(rule.users).toContainEqual("user-example"); | ||
expect(rule.teams).toBeUndefined(); | ||
}); | ||
|
||
test("should fail without reviewers", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: basic | ||
`); | ||
await expect(runner.getConfigFile("")).rejects.toThrowError('"value" must contain at least one of [users, teams]'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters