Skip to content

Commit

Permalink
test: fixed test for user limits
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jan 4, 2025
1 parent 3d1db38 commit 46b5c2d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/types/plugin-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum Role {
// These correspond to getMembershipForUser and getCollaboratorPermissionLevel for a user.
// Anything outside these values is considered to be a contributor (external user).
export const ADMIN_ROLES = ["admin", "owner", "billing_manager"];
export const COLLABORATOR_ROLES = ["write", "member"];
export const COLLABORATOR_ROLES = ["write", "member", "collaborator"];

const rolesWithReviewAuthority = T.Array(T.Enum(Role), {
default: [Role.OWNER, Role.ADMIN, Role.MEMBER, Role.COLLABORATOR],
Expand Down
31 changes: 15 additions & 16 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ type PayloadSender = Context["payload"]["sender"];

const octokit = jest.requireActual("@octokit/rest");
const TEST_REPO = "ubiquity/test-repo";
const PRIORITY_ONE = { name: "Priority: 1 (Normal)", roles: ["admin", "member", "collaborator", "contributor", "owner", "billing_manager"] };
const PRIORITY_ONE = { name: "Priority: 1 (Normal)", allowedRoles: ["collaborator", "contributor"] };
const priority3LabelName = "Priority: 3 (High)";
const priority4LabelName = "Priority: 4 (Urgent)";
const priority5LabelName = "Priority: 5 (Emergency)";
const PRIORITY_LABELS = [
PRIORITY_ONE,
{
name: "Priority: 2 (Medium)",
roles: ["admin", "member", "collaborator", "contributor", "owner", "billing_manager"],
allowedRoles: ["collaborator", "contributor"],
},
{
name: priority3LabelName,
roles: ["admin", "member", "collaborator", "contributor", "owner", "billing_manager"],
allowedRoles: ["collaborator", "contributor"],
},
{
name: priority4LabelName,
roles: ["admin", "member", "collaborator", "contributor", "owner", "billing_manager"],
allowedRoles: ["collaborator", "contributor"],
},
{
name: priority5LabelName,
roles: ["admin", "member", "collaborator", "contributor", "owner", "billing_manager"],
allowedRoles: ["collaborator", "contributor"],
},
];

Expand Down Expand Up @@ -240,7 +240,7 @@ describe("User start/stop", () => {
const issue = db.issue.findFirst({ where: { id: { equals: 1 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 5 } } }) as unknown as Sender;

const memberLimit = maxConcurrentDefaults.member;
const memberLimit = maxConcurrentDefaults.collaborator;

createIssuesForMaxAssignment(memberLimit + 4, sender.id);
const context = createContext(issue, sender) as unknown as Context;
Expand Down Expand Up @@ -309,9 +309,9 @@ describe("User start/stop", () => {
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender, "/start", "1", false, [
{ name: priority3LabelName, roles: ["admin", "member", "collaborator", "contributor", "owner", "billing_manager"] },
{ name: priority4LabelName, roles: ["admin", "member", "collaborator", "contributor", "owner", "billing_manager"] },
{ name: priority5LabelName, roles: ["admin", "member", "collaborator", "contributor", "owner", "billing_manager"] },
{ name: priority3LabelName, allowedRoles: ["collaborator", "contributor"] },
{ name: priority4LabelName, allowedRoles: ["collaborator", "contributor"] },
{ name: priority5LabelName, allowedRoles: ["collaborator", "contributor"] },
]) as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context);
Expand All @@ -328,11 +328,11 @@ describe("User start/stop", () => {
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender, "/start", "1", false, [
{ name: "Priority: 1 (Normal)", roles: ["contributor"] },
{ name: "Priority: 2 (Medium)", roles: ["contributor"] },
{ name: priority3LabelName, roles: ["contributor"] },
{ name: priority4LabelName, roles: ["contributor"] },
{ name: priority5LabelName, roles: ["contributor"] },
{ name: "Priority: 1 (Normal)", allowedRoles: ["contributor"] },
{ name: "Priority: 2 (Medium)", allowedRoles: ["contributor"] },
{ name: priority3LabelName, allowedRoles: ["contributor"] },
{ name: priority4LabelName, allowedRoles: ["contributor"] },
{ name: priority5LabelName, allowedRoles: ["contributor"] },
]) as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context);
Expand Down Expand Up @@ -695,8 +695,7 @@ function createIssuesForMaxAssignment(n: number, userId: number) {
}

const maxConcurrentDefaults = {
admin: Infinity,
member: 6,
collaborator: 6,
contributor: 4,
};

Expand Down
9 changes: 4 additions & 5 deletions tests/roles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { Context } from "../src/types";
describe("Role tests", () => {
it("Should retrieve the user role from organization", async () => {
const maxConcurrentTasks = {
contributor: 2,
admin: 100,
read: 1,
collaborator: 2,
contributor: 1,
};
const ctx = {
payload: {
Expand Down Expand Up @@ -36,7 +35,7 @@ describe("Role tests", () => {
} as unknown as Context;

let result = await getUserRoleAndTaskLimit(ctx, "ubiquity-os");
expect(result).toEqual({ limit: maxConcurrentTasks.admin, role: "admin" });
expect(result).toEqual({ limit: Infinity, role: "admin" });
ctx.octokit = {
rest: {
repos: {
Expand All @@ -45,6 +44,6 @@ describe("Role tests", () => {
},
} as unknown as Context["octokit"];
result = await getUserRoleAndTaskLimit(ctx, "ubiquity-os");
expect(result).toEqual({ limit: maxConcurrentTasks.read, role: "read" });
expect(result).toEqual({ limit: 1, role: "read" });
});
});

0 comments on commit 46b5c2d

Please sign in to comment.