Skip to content

Commit

Permalink
formated the code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Bullrich committed Jan 29, 2024
1 parent 188f17b commit 4573096
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { GitHubChecksApi } from "../github/check";
import { PullRequestApi } from "../github/pullRequest";
import { GitHubTeamsApi } from "../github/teams";
import { ActionLogger, GitHubClient, TeamApi } from "../github/types";
import { ActionRunner } from "../runner";
import { PolkadotFellows } from "../polkadot/fellows";
import { ActionRunner } from "../runner";

type ReportName =
| "CI files"
Expand Down
4 changes: 2 additions & 2 deletions src/test/rules/andDistinct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { mock, MockProxy } from "jest-mock-extended";

import { GitHubChecksApi } from "../../github/check";
import { PullRequestApi } from "../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../github/types";
import { ActionLogger } from "../../github/types";
import { PolkadotFellows } from "../../polkadot/fellows";
import { AndDistinctRule } from "../../rules/types";
import { ActionRunner } from "../../runner";
import { PolkadotFellows } from "../../polkadot/fellows";

describe("'AndDistinctRule' rule parsing", () => {
let api: MockProxy<PullRequestApi>;
Expand Down
4 changes: 2 additions & 2 deletions src/test/rules/andRule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { mock, MockProxy } from "jest-mock-extended";

import { GitHubChecksApi } from "../../github/check";
import { PullRequestApi } from "../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../github/types";
import { ActionLogger } from "../../github/types";
import { PolkadotFellows } from "../../polkadot/fellows";
import { AndRule } from "../../rules/types";
import { ActionRunner } from "../../runner";
import { PolkadotFellows } from "../../polkadot/fellows";

describe("'And' rule parsing", () => {
let api: MockProxy<PullRequestApi>;
Expand Down
4 changes: 2 additions & 2 deletions src/test/rules/basicRule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { mock, MockProxy } from "jest-mock-extended";

import { GitHubChecksApi } from "../../github/check";
import { PullRequestApi } from "../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../github/types";
import { ActionLogger } from "../../github/types";
import { PolkadotFellows } from "../../polkadot/fellows";
import { BasicRule } from "../../rules/types";
import { ActionRunner } from "../../runner";
import { PolkadotFellows } from "../../polkadot/fellows";

describe("Basic rule parsing", () => {
let api: MockProxy<PullRequestApi>;
Expand Down
2 changes: 1 addition & 1 deletion src/test/rules/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { mock, MockProxy } from "jest-mock-extended";
import { GitHubChecksApi } from "../../github/check";
import { PullRequestApi } from "../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../github/types";
import { PolkadotFellows } from "../../polkadot/fellows";
import { RuleTypes } from "../../rules/types";
import { ActionRunner } from "../../runner";
import { PolkadotFellows } from "../../polkadot/fellows";

describe("Config Parsing", () => {
let api: MockProxy<PullRequestApi>;
Expand Down
10 changes: 8 additions & 2 deletions src/test/rules/fellows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ import { mock, MockProxy } from "jest-mock-extended";
import { GitHubChecksApi } from "../../github/check";
import { PullRequestApi } from "../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../github/types";
import { PolkadotFellows } from "../../polkadot/fellows";
import { FellowsRule } from "../../rules/types";
import { ActionRunner } from "../../runner";
import { PolkadotFellows } from "../../polkadot/fellows";

describe("Fellows rule parsing", () => {
let api: MockProxy<PullRequestApi>;
let runner: ActionRunner;
beforeEach(() => {
api = mock<PullRequestApi>();
runner = new ActionRunner(api, mock<TeamApi>(), mock<PolkadotFellows>(), mock<GitHubChecksApi>(), mock<ActionLogger>());
runner = new ActionRunner(
api,
mock<TeamApi>(),
mock<PolkadotFellows>(),
mock<GitHubChecksApi>(),
mock<ActionLogger>(),
);
});
test("should get minimal config", async () => {
api.getConfigFile.mockResolvedValue(`
Expand Down
2 changes: 1 addition & 1 deletion src/test/rules/or.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { mock, MockProxy } from "jest-mock-extended";
import { GitHubChecksApi } from "../../github/check";
import { PullRequestApi } from "../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../github/types";
import { PolkadotFellows } from "../../polkadot/fellows";
import { OrRule } from "../../rules/types";
import { ActionRunner } from "../../runner";
import { PolkadotFellows } from "../../polkadot/fellows";

describe("'Or' rule parsing", () => {
let api: MockProxy<PullRequestApi>;
Expand Down
2 changes: 1 addition & 1 deletion src/test/runner/conditions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { mock, MockProxy } from "jest-mock-extended";
import { GitHubChecksApi } from "../../github/check";
import { PullRequestApi } from "../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../github/types";
import { ActionRunner } from "../../runner";
import { PolkadotFellows } from "../../polkadot/fellows";
import { ActionRunner } from "../../runner";

describe("evaluateCondition tests", () => {
let api: MockProxy<PullRequestApi>;
Expand Down
2 changes: 1 addition & 1 deletion src/test/runner/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { ReviewFailure } from "../../failures";
import { GitHubChecksApi } from "../../github/check";
import { PullRequestApi } from "../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../github/types";
import { PolkadotFellows } from "../../polkadot/fellows";
import { ConfigurationFile, Rule, RuleTypes } from "../../rules/types";
import { ActionRunner } from "../../runner";
import { PolkadotFellows } from "../../polkadot/fellows";

describe("Shared validations", () => {
let api: MockProxy<PullRequestApi>;
Expand Down
2 changes: 1 addition & 1 deletion src/test/runner/validation/and.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { mock, MockProxy } from "jest-mock-extended";
import { GitHubChecksApi } from "../../../github/check";
import { PullRequestApi } from "../../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../../github/types";
import { PolkadotFellows } from "../../../polkadot/fellows";
import { ConfigurationFile, RuleTypes } from "../../../rules/types";
import { ActionRunner } from "../../../runner";
import { PolkadotFellows } from "../../../polkadot/fellows";

describe("'And' rule validation", () => {
let api: MockProxy<PullRequestApi>;
Expand Down
2 changes: 1 addition & 1 deletion src/test/runner/validation/andDistinct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { mock, MockProxy } from "jest-mock-extended";
import { GitHubChecksApi } from "../../../github/check";
import { PullRequestApi } from "../../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../../github/types";
import { PolkadotFellows } from "../../../polkadot/fellows";
import { AndDistinctRule, RuleTypes } from "../../../rules/types";
import { ActionRunner } from "../../../runner";
import { PolkadotFellows } from "../../../polkadot/fellows";

describe("'And distinct' rule validation", () => {
let api: MockProxy<PullRequestApi>;
Expand Down
96 changes: 76 additions & 20 deletions src/test/runner/validation/fellows.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { validate } from "@eng-automation/js";
import { mock, MockProxy } from "jest-mock-extended";

import { FellowMissingRankFailure } from "../../../failures";
import { FellowMissingRankFailure, FellowMissingScoreFailure } from "../../../failures";
import { GitHubChecksApi } from "../../../github/check";
import { PullRequestApi } from "../../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../../github/types";
import { PolkadotFellows } from "../../../polkadot/fellows";
import { ConfigurationFile, FellowsScore, RuleTypes } from "../../../rules/types";
import { fellowScoreSchema } from "../../../rules/validator";
import { ActionRunner } from "../../../runner";
import { PolkadotFellows } from "../../../polkadot/fellows";

describe("'Fellows' rule validation", () => {
let api: MockProxy<PullRequestApi>;
Expand Down Expand Up @@ -105,7 +105,6 @@ describe("'Fellows' rule validation", () => {

test("should throw error if not enough fellows of a given rank are found to fulfill minApprovals requirement", async () => {
fellowsApi.getTeamMembers.mockResolvedValue([users[2]]);
fellowsApi.getTeamMembers.calledWith("4").mockResolvedValue(users);
const config: ConfigurationFile = {
rules: [
{
Expand All @@ -124,30 +123,87 @@ describe("'Fellows' rule validation", () => {
});
});

// TODO: Add more details to these rules
describe("Score Validation", () => {
test("should not report errors with a valid schema", () => {
const score = {};
validate<FellowsScore>(score, fellowScoreSchema);
beforeEach(() => {
fellowsApi.getTeamMembers.mockResolvedValue([users[2]]);
api.listApprovedReviewsAuthors.mockResolvedValue(users);
});

test("should assign correct values", () => {
const score = { dan1: 3, dan3: 5 };
const validation: FellowsScore = validate(score, fellowScoreSchema);
expect(validation.dan1).toBe(3);
expect(validation.dan3).toBe(5);
const generateSchemaWithScore = (minScore: number): ConfigurationFile => {
return {
rules: [
{
name: "Score rule",
type: RuleTypes.Fellows,
condition: { include: ["review-bot.yml"] },
minRank: 1,
minApprovals: 1,
minScore,
},
],
score: {
dan1: 1,
dan2: 2,
dan3: 3,
dan4: 4,
dan5: 5,
dan6: 6,
dan7: 7,
dan8: 8,
dan9: 9,
},
};
};

describe("Schema test", () => {
test("should not report errors with a valid schema", () => {
const score = {};
validate<FellowsScore>(score, fellowScoreSchema);
});

test("should assign correct values", () => {
const score = { dan1: 3, dan3: 5 };
const validation: FellowsScore = validate(score, fellowScoreSchema);
expect(validation.dan1).toBe(3);
expect(validation.dan3).toBe(5);
});

test("should default unassigned values as 0", () => {
const score = { dan1: 3 };
const validation: FellowsScore = validate(score, fellowScoreSchema);
expect(validation.dan2).toBe(0);
expect(validation.dan5).toBe(0);
});

test("should fail when a score is not a number", () => {
const score = { dan1: "one" };
expect(() => validate(score, fellowScoreSchema)).toThrowError('"dan1" must be a number');
});
});

test("should work with enough score", async () => {
fellowsApi.listFellows.mockResolvedValue([[users[2], 4]]);

const { reports } = await runner.validatePullRequest(generateSchemaWithScore(1));
expect(reports).toHaveLength(0);
});

test("should default unassigned values as 0", () => {
const score = { dan1: 3 };
const validation: FellowsScore = validate(score, fellowScoreSchema);
expect(validation.dan2).toBe(0);
expect(validation.dan5).toBe(0);
test("should fail without enough score", async () => {
fellowsApi.listFellows.mockResolvedValue([[users[2], 4]]);

const { reports } = await runner.validatePullRequest(generateSchemaWithScore(5));
const error = reports[0] as FellowMissingScoreFailure;
expect(error.currentScore).toBeLessThan(5);
});

test("should fail when a score is not a number", () => {
const score = { dan1: "one" };
expect(() => validate(score, fellowScoreSchema)).toThrowError('"dan1" must be a number');
test("should allow a combination of scores", async () => {
fellowsApi.listFellows.mockResolvedValue([
[users[0], 4],
[users[1], 1],
]);

const { reports } = await runner.validatePullRequest(generateSchemaWithScore(1));
expect(reports).toHaveLength(0);
});
});
});
2 changes: 1 addition & 1 deletion src/test/runner/validation/or.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { mock, MockProxy } from "jest-mock-extended";
import { GitHubChecksApi } from "../../../github/check";
import { PullRequestApi } from "../../../github/pullRequest";
import { ActionLogger, TeamApi } from "../../../github/types";
import { PolkadotFellows } from "../../../polkadot/fellows";
import { ConfigurationFile, RuleTypes } from "../../../rules/types";
import { ActionRunner } from "../../../runner";
import { PolkadotFellows } from "../../../polkadot/fellows";

describe("'Or' rule validation", () => {
let api: MockProxy<PullRequestApi>;
Expand Down

0 comments on commit 4573096

Please sign in to comment.