From df63472ee8ee616f89fd2038c180bc2847a6e73c Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Sun, 5 Jan 2025 01:41:49 +0900 Subject: [PATCH] test: fixed test for user limits --- .../shared/get-user-task-limit-and-role.ts | 4 +- src/handlers/shared/start.ts | 4 +- tests/__mocks__/valid-configuration.json | 37 +++++++++---------- tests/configuration.test.ts | 16 ++++---- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/handlers/shared/get-user-task-limit-and-role.ts b/src/handlers/shared/get-user-task-limit-and-role.ts index e530cc09..56eccfe9 100644 --- a/src/handlers/shared/get-user-task-limit-and-role.ts +++ b/src/handlers/shared/get-user-task-limit-and-role.ts @@ -6,11 +6,11 @@ interface MatchingUserProps { } export function isAdminRole(role: string) { - return ADMIN_ROLES.includes(role); + return ADMIN_ROLES.includes(role.toLowerCase()); } export function isCollaboratorRole(role: string) { - return COLLABORATOR_ROLES.includes(role); + return COLLABORATOR_ROLES.includes(role.toLowerCase()); } export function getUserTaskLimit(maxConcurrentTasks: PluginSettings["maxConcurrentTasks"], role: string) { diff --git a/src/handlers/shared/start.ts b/src/handlers/shared/start.ts index 3c94de95..a04af9de 100644 --- a/src/handlers/shared/start.ts +++ b/src/handlers/shared/start.ts @@ -5,7 +5,7 @@ import { HttpStatusCode, Result } from "../result-types"; import { hasUserBeenUnassigned } from "./check-assignments"; import { checkTaskStale } from "./check-task-stale"; import { generateAssignmentComment } from "./generate-assignment-comment"; -import { getUserRoleAndTaskLimit } from "./get-user-task-limit-and-role"; +import { getUserRoleAndTaskLimit, isAdminRole, isCollaboratorRole } from "./get-user-task-limit-and-role"; import structuredMetadata from "./structured-metadata"; import { assignTableComment } from "./table"; @@ -31,7 +31,7 @@ async function checkRequirements(context: Context, issue: Context<"issue_comment issue: issue.html_url, } ); - } else if (!currentLabelConfiguration.roles.includes(userAssociation.role.toLowerCase() as (typeof currentLabelConfiguration.roles)[number])) { + } else if (!isAdminRole(userAssociation.role) && !isCollaboratorRole(userAssociation.role)) { // If we found the label in the allowed list, but the user role does not match the allowed roles, then the user cannot start this task. throw logger.error("You must be a core team member to start this task", { currentLabelConfiguration, diff --git a/tests/__mocks__/valid-configuration.json b/tests/__mocks__/valid-configuration.json index 39807ebd..6018f88b 100644 --- a/tests/__mocks__/valid-configuration.json +++ b/tests/__mocks__/valid-configuration.json @@ -1,35 +1,34 @@ { - "reviewDelayTolerance": "1 Day", - "taskStaleTimeoutDuration": "30 Days", - "startRequiresWallet": true, + "assignedIssueScope": "org", + "emptyWalletText": "Please set your wallet address with the /wallet command first and try again.", "maxConcurrentTasks": { - "admin": 20, - "member": 10, + "collaborator": 10, "contributor": 2 }, - "assignedIssueScope": "org", - "emptyWalletText": "Please set your wallet address with the /wallet command first and try again.", - "rolesWithReviewAuthority": ["OWNER", "ADMIN", "MEMBER"], "requiredLabelsToStart": [ { - "name": "Priority: 1 (Normal)", - "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + "allowedRoles": ["collaborator", "contributor"], + "name": "Priority: 1 (Normal)" }, { - "name": "Priority: 2 (Medium)", - "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + "allowedRoles": ["collaborator", "contributor"], + "name": "Priority: 2 (Medium)" }, { - "name": "Priority: 3 (High)", - "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + "allowedRoles": ["collaborator", "contributor"], + "name": "Priority: 3 (High)" }, { - "name": "Priority: 4 (Urgent)", - "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + "allowedRoles": ["collaborator", "contributor"], + "name": "Priority: 4 (Urgent)" }, { - "name": "Priority: 5 (Emergency)", - "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + "allowedRoles": ["collaborator", "contributor"], + "name": "Priority: 5 (Emergency)" } - ] + ], + "reviewDelayTolerance": "1 Day", + "rolesWithReviewAuthority": ["OWNER", "ADMIN", "MEMBER"], + "startRequiresWallet": true, + "taskStaleTimeoutDuration": "30 Days" } diff --git a/tests/configuration.test.ts b/tests/configuration.test.ts index ee5fe249..43ee8415 100644 --- a/tests/configuration.test.ts +++ b/tests/configuration.test.ts @@ -3,11 +3,11 @@ import { AssignedIssueScope, PluginSettings, pluginSettingsSchema, Role } from " import cfg from "./__mocks__/valid-configuration.json"; const PRIORITY_LABELS = [ - { name: "Priority: 1 (Normal)", roles: ["admin", "member", "contributor", "owner", "billing_manager"] }, - { name: "Priority: 2 (Medium)", roles: ["admin", "member", "contributor", "owner", "billing_manager"] }, - { name: "Priority: 3 (High)", roles: ["admin", "member", "contributor", "owner", "billing_manager"] }, - { name: "Priority: 4 (Urgent)", roles: ["admin", "member", "contributor", "owner", "billing_manager"] }, - { name: "Priority: 5 (Emergency)", roles: ["admin", "member", "contributor", "owner", "billing_manager"] }, + { name: "Priority: 1 (Normal)", allowedRoles: ["collaborator", "contributor"] }, + { name: "Priority: 2 (Medium)", allowedRoles: ["collaborator", "contributor"] }, + { name: "Priority: 3 (High)", allowedRoles: ["collaborator", "contributor"] }, + { name: "Priority: 4 (Urgent)", allowedRoles: ["collaborator", "contributor"] }, + { name: "Priority: 5 (Emergency)", allowedRoles: ["collaborator", "contributor"] }, ]; describe("Configuration tests", () => { @@ -18,18 +18,18 @@ describe("Configuration tests", () => { startRequiresWallet: true, assignedIssueScope: AssignedIssueScope.ORG, emptyWalletText: "Please set your wallet address with the /wallet command first and try again.", - maxConcurrentTasks: { admin: 20, member: 10, contributor: 2 }, + maxConcurrentTasks: { collaborator: 10, contributor: 2 }, rolesWithReviewAuthority: [Role.OWNER, Role.ADMIN, Role.MEMBER], requiredLabelsToStart: PRIORITY_LABELS, }) as PluginSettings; expect(settings).toEqual(cfg); }); - it("Should default the admin to infinity if missing from config when decoded", () => { + it("Should give the collaborator limits of PRs", () => { const settings = Value.Default(pluginSettingsSchema, { requiredLabelsToStart: PRIORITY_LABELS, }) as PluginSettings; console.dir([...Value.Errors(pluginSettingsSchema, settings)]); const decodedSettings = Value.Decode(pluginSettingsSchema, settings); - expect(decodedSettings.maxConcurrentTasks["admin"]).toEqual(Infinity); + expect(decodedSettings.maxConcurrentTasks["collaborator"]).toEqual(10); }); });