Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import { describe, expect, it, vi } from "vitest";
// @carbon/auth builds its Supabase client at import time.
vi.mock("@carbon/auth/client.server", () => ({
getCarbonServiceRole: vi.fn()
}));
const { purgeRefusal, resolvePurgeOptions } = await import(
"./purge-inactive-companies"
);
describe("purgeRefusal", () => {
it("allows only a dashboard invoke on Cloud", () => {
expect(purgeRefusal("inngest/function.invoked", "cloud")).toBeNull();
});
it.each([
["a sent event", "carbon/purge-inactive-companies", "cloud"],
["a cron tick", "inngest/scheduled.timer", "cloud"],
["Community", "inngest/function.invoked", "community"],
["Enterprise", "inngest/function.invoked", "enterprise"],
["no edition", "inngest/function.invoked", undefined]
])("refuses %s", (_label, name, edition) => {
expect(purgeRefusal(name, edition)).not.toBeNull();
});
});
describe("resolvePurgeOptions", () => {
it.each([
["an empty payload", {}],
["dryRun true", { dryRun: true }],
["the string false", { dryRun: "false" }],
["zero", { dryRun: 0 }],
["null", { dryRun: null }]
])("is a dry run for %s", (_label, data) => {
expect(resolvePurgeOptions(data).dryRun).toBe(true);
});
it("deletes only for dryRun false", () => {
expect(resolvePurgeOptions({ dryRun: false }).dryRun).toBe(false);
});
it("caps a run at 500 companies and never goes below zero", () => {
expect(resolvePurgeOptions({}).limit).toBe(500);
expect(resolvePurgeOptions({ limit: 5000 }).limit).toBe(500);
expect(resolvePurgeOptions({ limit: 25.9 }).limit).toBe(25);
expect(resolvePurgeOptions({ limit: -3 }).limit).toBe(0);
expect(resolvePurgeOptions({ limit: "50" }).limit).toBe(500);
});
});