Skip to content

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.

Merge pull request #2023 from crbnos/fix/update-item-readable-id

BettrCallRaul7185bda6d35e
diff --cc apps/erp/test/items-operations.test.ts
index 6a5c1eaf2c,96e5d86fdb..a8caa4d957
--- a/apps/erp/test/items-operations.test.ts
+++ b/apps/erp/test/items-operations.test.ts
@@@ -20,8 -34,16 +20,9 @@@ import
setItemActive,
setItemPostingGroup,
setItemSourcing,
+ updateItem,
updateItemPlanning
} from "../app/modules/items/items.server";
-import {
- getItemSupersession,
- updateChangeNoticeStatus,
- updateItemMethodAndSourcing,
- upsertItemPlanning,
- upsertItemSupersession
-} from "../app/modules/items/items.service";
import { createServiceContext } from "@carbon/api/service-fn.server";
type Write = {
@@@ -288,6 -318,65 +289,65 @@@ describe("updateItemPlanning", () =>
});
expect(result.error).toMatchObject({ category: "rule" });
- expect(upsertItemPlanning).not.toHaveBeenCalled();
+ expect(writes).toEqual([]);
});
});
+
+ describe("updateItem", () => {
+ const part = {
+ id: "i1",
+ name: "Bracket",
+ replenishmentSystem: "Buy",
+ defaultMethodType: "Purchase to Order",
+ itemTrackingType: "Inventory",
+ unitOfMeasureCode: "EA",
+ type: "Part"
+ } as const;
+
+ it("refuses a readable id that differs from the item's, and writes nothing", async () => {
+ const { client, writes } = fakeClient({ item: { readableId: "P-100" } });
+
+ for (const readableId of ["P-200", ""]) {
+ const result = await updateItem(contextFor(client), {
+ ...part,
+ readableId
+ });
+
+ expect(result.error).toMatchObject({ category: "rule" });
+ expect(result.error?.message).toContain("setItemReadableId");
+ }
+ expect(writes).toHaveLength(0);
+ });
+
+ it("refuses an item that is not of the type sent, and writes nothing", async () => {
+ const { client, writes } = fakeClient({ item: null });
+
+ const result = await updateItem(contextFor(client), {
+ ...part,
+ type: "Tool"
+ });
+
+ expect(result.error).toMatchObject({ category: "rule" });
+ expect(writes).toHaveLength(0);
+ });
+
+ it("writes neither the readable id nor the type", async () => {
+ const { client, writes } = fakeClient({ item: { readableId: "P-100" } });
+
+ const result = await updateItem(contextFor(client), {
+ ...part,
+ readableId: "P-100",
+ name: "Bracket, painted"
+ });
+
+ expect(result.error).toBeNull();
+ expect(writes).toHaveLength(1);
+ expect(writes[0]).toMatchObject({
+ table: "item",
+ op: "update",
+ values: { name: "Bracket, painted" }
+ });
+ expect(writes[0].values).not.toHaveProperty("readableId");
+ expect(writes[0].values).not.toHaveProperty("type");
+ });
+ });