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 3d6f4af commit df63472
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/handlers/shared/get-user-task-limit-and-role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/shared/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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,
Expand Down
37 changes: 18 additions & 19 deletions tests/__mocks__/valid-configuration.json
Original file line number Diff line number Diff line change
@@ -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"
}
16 changes: 8 additions & 8 deletions tests/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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);
});
});

0 comments on commit df63472

Please sign in to comment.