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.

1.9 KB
Raw Blame
// 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 type { Database } from "@carbon/database";
import { describe, expect, it } from "vitest";
import { getLineDescription } from "./purchase-order";

type Line = Database["public"]["Views"]["purchaseOrderLines"]["Row"];
const line = (overrides: Partial<Line>) =>
  ({ purchaseOrderLineType: "Part", ...overrides }) as Line;

// `itemReadableId` is the view's `readableIdWithRevision`, so it is the only
// place the revision reaches the document.
describe("getLineDescription", () => {
  it("shows the item id on its own when there is no supplier part number", () => {
    expect(getLineDescription(line({ itemReadableId: "P000123.B" }))).toBe(
      "P000123.B"
    );
    expect(
      getLineDescription(
        line({ itemReadableId: "P000123.B", supplierPartId: "" })
      )
    ).toBe("P000123.B");
  });

  it("keeps the item id and revision next to the supplier part number", () => {
    expect(
      getLineDescription(
        line({ itemReadableId: "P000123.B", supplierPartId: "SUP-778" })
      )
    ).toBe("P000123.B (SUP-778)");
    expect(
      getLineDescription(
        line({
          itemReadableId: "P000123.B",
          supplierPartId: "",
          supplierPartIdFromSupplier: "SUP-778"
        })
      )
    ).toBe("P000123.B (SUP-778)");
  });

  it("does not repeat a supplier part number that equals the item id", () => {
    expect(
      getLineDescription(
        line({ itemReadableId: "P000123.B", supplierPartId: "P000123.B" })
      )
    ).toBe("P000123.B");
  });

  it("falls back to the supplier part number when the line has no item", () => {
    expect(
      getLineDescription(
        line({ itemReadableId: null, supplierPartId: "SUP-778" })
      )
    ).toBe("SUP-778");
  });
});