Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+47
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { assertMassActionAllowed, massActionErrors, previewMassAction } from "./mass-action.js";
|
||||
import { CatalogError } from "./errors.js";
|
||||
|
||||
describe("previewMassAction sampling edge cases", () => {
|
||||
test("yields an empty sample when no items are supplied", () => {
|
||||
const preview = previewMassAction({ affected: 120, policy: { confirmThreshold: 50 } });
|
||||
expect(preview.sample).toEqual([]);
|
||||
expect(preview.requiresConfirmation).toBe(true);
|
||||
expect(preview.exceedsHardLimit).toBe(false);
|
||||
});
|
||||
|
||||
test("clamps a negative sample size to zero", () => {
|
||||
const preview = previewMassAction({ affected: 3, items: [1, 2, 3], sampleSize: -5, policy: { confirmThreshold: 50 } });
|
||||
expect(preview.sample).toEqual([]);
|
||||
});
|
||||
|
||||
test("does not require confirmation once the hard limit is exceeded", () => {
|
||||
const preview = previewMassAction({ affected: 9000, items: [], policy: { confirmThreshold: 50, hardLimit: 5000 } });
|
||||
expect(preview.exceedsHardLimit).toBe(true);
|
||||
expect(preview.requiresConfirmation).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("assertMassActionAllowed detail propagation", () => {
|
||||
test("merges caller-supplied details into a hard-limit error", () => {
|
||||
try {
|
||||
assertMassActionAllowed({ affected: 6000, policy: { confirmThreshold: 50, hardLimit: 5000 } }, { tenantId: "tenant_1" });
|
||||
throw new Error("expected throw");
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(CatalogError);
|
||||
expect((error as CatalogError).code).toBe(massActionErrors.exceedsLimit.code);
|
||||
expect((error as CatalogError).details).toMatchObject({ affected: 6000, hardLimit: 5000, tenantId: "tenant_1" });
|
||||
}
|
||||
});
|
||||
|
||||
test("merges caller-supplied details into a confirmation-required error", () => {
|
||||
try {
|
||||
assertMassActionAllowed({ affected: 200, policy: { confirmThreshold: 50 } }, { actor: "user_1" });
|
||||
throw new Error("expected throw");
|
||||
} catch (error) {
|
||||
expect((error as CatalogError).code).toBe(massActionErrors.confirmationRequired.code);
|
||||
expect((error as CatalogError).details).toMatchObject({ affected: 200, confirmThreshold: 50, actor: "user_1" });
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user