Fix PrGateRules tests for checkRepoAccess refactor

Update test imports, mock data, and evaluate calls to match the
checkOrgMember/author_association → checkRepoAccess/getRepoPermission
rename in 0ab437ed5.
This commit is contained in:
evanpelle
2026-06-04 16:45:46 -07:00
parent 37b7a781c2
commit 00a7b6d14d
+19 -15
View File
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from "vitest";
import { import {
checkApprovedWork, checkApprovedWork,
checkBypass, checkBypass,
checkOrgMember, checkRepoAccess,
checkSmallFix, checkSmallFix,
evaluate, evaluate,
parseLinkedIssues, parseLinkedIssues,
@@ -88,7 +88,6 @@ const makePR = (overrides: Partial<PRMetadata> = {}): PRMetadata => ({
number: 1, number: 1,
body: null, body: null,
user: { login: "alice" }, user: { login: "alice" },
author_association: "CONTRIBUTOR",
labels: [], labels: [],
...overrides, ...overrides,
}); });
@@ -110,20 +109,20 @@ describe("checkBypass", () => {
}); });
}); });
describe("checkOrgMember", () => { describe("checkRepoAccess", () => {
it("passes for OWNER, MEMBER, COLLABORATOR", () => { it("passes for admin, maintain, write permissions", async () => {
for (const assoc of ["OWNER", "MEMBER", "COLLABORATOR"]) { for (const permission of ["admin", "maintain", "write"]) {
expect(checkOrgMember(makePR({ author_association: assoc })).action).toBe( const get = vi.fn(async () => permission);
"pass", const r = await checkRepoAccess(makePR(), get);
); expect(r.action).toBe("pass");
} }
}); });
it("returns next for untrusted associations", () => { it("returns next for untrusted permissions", async () => {
for (const assoc of ["CONTRIBUTOR", "NONE", "FIRST_TIME_CONTRIBUTOR"]) { for (const permission of ["read", "none", "triage"]) {
expect(checkOrgMember(makePR({ author_association: assoc })).action).toBe( const get = vi.fn(async () => permission);
"next", const r = await checkRepoAccess(makePR(), get);
); expect(r.action).toBe("next");
} }
}); });
}); });
@@ -238,15 +237,17 @@ describe("evaluate (priority ordering)", () => {
makePR({ labels: ["bypass-pr-check"] }), makePR({ labels: ["bypass-pr-check"] }),
[{ additions: 5000, deletions: 0 }], [{ additions: 5000, deletions: 0 }],
async () => null, async () => null,
async () => "none",
); );
expect(r.action).toBe("pass"); expect(r.action).toBe("pass");
}); });
it("rule 1 — org member with a huge PR passes", async () => { it("rule 1 — repo write access with a huge PR passes", async () => {
const r = await evaluate( const r = await evaluate(
makePR({ author_association: "MEMBER" }), makePR(),
[{ additions: 5000, deletions: 0 }], [{ additions: 5000, deletions: 0 }],
async () => null, async () => null,
async () => "write",
); );
expect(r.action).toBe("pass"); expect(r.action).toBe("pass");
}); });
@@ -256,6 +257,7 @@ describe("evaluate (priority ordering)", () => {
makePR(), makePR(),
[{ additions: 10, deletions: 5 }], [{ additions: 10, deletions: 5 }],
async () => null, async () => null,
async () => "none",
); );
expect(r.action).toBe("pass"); expect(r.action).toBe("pass");
if (r.action === "pass") expect(r.labelToAdd).toBe("small-fix"); if (r.action === "pass") expect(r.labelToAdd).toBe("small-fix");
@@ -266,6 +268,7 @@ describe("evaluate (priority ordering)", () => {
makePR({ body: "Closes #5" }), makePR({ body: "Closes #5" }),
[{ additions: 200, deletions: 50 }], [{ additions: 200, deletions: 50 }],
async () => makeIssue(), async () => makeIssue(),
async () => "none",
); );
expect(r.action).toBe("pass"); expect(r.action).toBe("pass");
}); });
@@ -275,6 +278,7 @@ describe("evaluate (priority ordering)", () => {
makePR(), makePR(),
[{ additions: 200, deletions: 50 }], [{ additions: 200, deletions: 50 }],
async () => null, async () => null,
async () => "none",
); );
expect(r.action).toBe("close"); expect(r.action).toBe("close");
}); });