fix(housekeeping): complete people workflow fidelity
This commit is contained in:
1 parent
25b76437ff
commit
91c9efcbb4
29 files changed
+1365
-290
No files matched your search
@@ -95,6 +95,50 @@ describe("People community and staff commands", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
[
|
||||
"people.application.decide",
|
||||
{ applicationId: "9007199254740993", decision: "dismiss" },
|
||||
],
|
||||
["people.team.change", { action: "delete", teamId: "9007199254740993" }],
|
||||
[
|
||||
"people.ip.action",
|
||||
{ action: "delete-blacklist", id: "9007199254740993" },
|
||||
],
|
||||
["people.word-filter.update", { action: "delete", id: "9007199254740993" }],
|
||||
] as const)(
|
||||
"accepts a canonical BIGINT identifier for %s",
|
||||
(commandId, input) => {
|
||||
const command = commands.find((entry) => entry.id === commandId);
|
||||
if (!command) throw new Error(`command missing: ${commandId}`);
|
||||
expect(command.input.safeParse(input).success).toBe(true);
|
||||
},
|
||||
);
|
||||
it.each([
|
||||
[
|
||||
"people.application.decide",
|
||||
{ applicationId: "18446744073709551616", decision: "dismiss" },
|
||||
],
|
||||
[
|
||||
"people.team.change",
|
||||
{ action: "delete", teamId: "18446744073709551616" },
|
||||
],
|
||||
[
|
||||
"people.ip.action",
|
||||
{ action: "delete-blacklist", id: "18446744073709551616" },
|
||||
],
|
||||
[
|
||||
"people.word-filter.update",
|
||||
{ action: "delete", id: "18446744073709551616" },
|
||||
],
|
||||
] as const)(
|
||||
"rejects an overflowing BIGINT identifier for %s",
|
||||
(commandId, input) => {
|
||||
const command = commands.find((entry) => entry.id === commandId);
|
||||
if (!command) throw new Error(`command missing: ${commandId}`);
|
||||
expect(command.input.safeParse(input).success).toBe(false);
|
||||
},
|
||||
);
|
||||
it("delegates the canonical operation without a redirect", async () => {
|
||||
const execute = vi.fn(async (context, operation, input) => ({
|
||||
ok: true as const,
|
||||
|
||||
@@ -53,6 +53,30 @@ function communityCommand<I>(
|
||||
}
|
||||
|
||||
const positiveId = z.number().int().positive();
|
||||
const MAX_UNSIGNED_BIGINT = "18446744073709551615";
|
||||
|
||||
function boundedDecimalPattern(maximum: string): RegExp {
|
||||
const alternatives = [`[1-9]\\d{0,${maximum.length - 2}}`];
|
||||
for (let index = 0; index < maximum.length; index += 1) {
|
||||
const maximumDigit = Number(maximum[index]);
|
||||
const minimumDigit = index === 0 ? 1 : 0;
|
||||
const upperDigit = maximumDigit - 1;
|
||||
if (upperDigit < minimumDigit) continue;
|
||||
const digit =
|
||||
upperDigit === minimumDigit
|
||||
? String(minimumDigit)
|
||||
: `[${minimumDigit}-${upperDigit}]`;
|
||||
alternatives.push(
|
||||
`${maximum.slice(0, index)}${digit}\\d{${maximum.length - index - 1}}`,
|
||||
);
|
||||
}
|
||||
alternatives.push(maximum);
|
||||
return new RegExp(`^(?:${alternatives.join("|")})$`, "u");
|
||||
}
|
||||
|
||||
const unsignedBigIntId = z
|
||||
.string()
|
||||
.regex(boundedDecimalPattern(MAX_UNSIGNED_BIGINT));
|
||||
const requiredText = (max: number) => z.string().min(1).max(max).regex(/\S/u);
|
||||
|
||||
export function createCommunityCommands(
|
||||
@@ -70,7 +94,7 @@ export function createCommunityCommands(
|
||||
operation: "application.decide",
|
||||
capability: PERMS.USERS_EDIT,
|
||||
input: z.object({
|
||||
applicationId: positiveId,
|
||||
applicationId: unsignedBigIntId,
|
||||
decision: z.literal("dismiss"),
|
||||
}),
|
||||
}),
|
||||
@@ -87,7 +111,7 @@ export function createCommunityCommands(
|
||||
staffColor: z.string().min(1).max(255).optional(),
|
||||
hiddenRank: z.boolean().optional(),
|
||||
}),
|
||||
z.object({ action: z.literal("delete"), teamId: positiveId }),
|
||||
z.object({ action: z.literal("delete"), teamId: unsignedBigIntId }),
|
||||
]),
|
||||
}),
|
||||
communityCommand(service, {
|
||||
@@ -102,7 +126,7 @@ export function createCommunityCommands(
|
||||
}),
|
||||
z.object({
|
||||
action: z.enum(["delete-whitelist", "delete-blacklist"]),
|
||||
id: positiveId,
|
||||
id: unsignedBigIntId,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
@@ -123,7 +147,7 @@ export function createCommunityCommands(
|
||||
capability: PERMS.WORDFILTER_EDIT,
|
||||
input: z.discriminatedUnion("action", [
|
||||
z.object({ action: z.literal("add"), word: requiredText(255) }),
|
||||
z.object({ action: z.literal("delete"), id: positiveId }),
|
||||
z.object({ action: z.literal("delete"), id: unsignedBigIntId }),
|
||||
]),
|
||||
}),
|
||||
] as const;
|
||||
|
||||
Reference in new issue
Block a user