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
test(production): stop mocking production.service in the job lifecycle tests
Raul67c8df721b75
diff --git a/apps/erp/test/database/serial-number-timing.test.ts b/apps/erp/test/database/serial-number-timing.test.tsindex f532ec65d9..6bf838c930 100644--- a/apps/erp/test/database/serial-number-timing.test.ts+++ b/apps/erp/test/database/serial-number-timing.test.ts@@ -53,12 +53,12 @@ vi.mock("@carbon/env", async (importOriginal) => {const client = hasLocalDatabase ? localServiceRoleClient() : null;-function contextFor(f: Fixture) {+function contextFor(f: Fixture, system: () => unknown = () => client) {return createServiceContext({actor: { type: "system", onBehalfOf: USER },company: { id: f.companyId, groupId: f.groupId },caller: client!,- system: () => client!,+ system: system as () => NonNullable<typeof client>,pg: () => f.db,kv: () => {throw new Error("completeJob reads no cache");@@ -421,6 +421,36 @@ describe.skipIf(!client)("serial number timing", () => {}});+ it("keeps the numbered completion and warns when returning picked material fails", async () => {+ const f = await alwaysPostFixture();+ try {+ await stockPart(f, 20);+ await serialSetup(f, "production");+ const job = await untouchedSerialJob(f, "sweep", 3);++ // A system client that is neither the service role nor signed in as the+ // user: the picked-material return refuses it after the completion committed.+ const result = await completeJob(+ contextFor(f, () => ({})),+ { jobId: job.jobId, quantityComplete: 2 }+ );++ expect(result).toEqual({+ data: {+ jobId: job.jobId,+ warning: "Job completed, but returning picked material failed"+ },+ error: null+ });+ expect(await receivedUnits(f, job.jobId)).toEqual([+ { readableId: "SN-001", quantity: 1 },+ { readableId: "SN-002", quantity: 1 }+ ]);+ } finally {+ await f.cleanup();+ }+ });+it("creates the units no row holds when a completion follows the shop floor", async () => {const f = await alwaysPostFixture();try {diff --git a/apps/erp/test/job-lifecycle.test.ts b/apps/erp/test/job-lifecycle.test.tsindex e5ad64c7f7..a0c1c8189c 100644--- a/apps/erp/test/job-lifecycle.test.ts+++ b/apps/erp/test/job-lifecycle.test.ts@@ -16,18 +16,9 @@ vi.mock("@carbon/planning", () => ({runMrp: vi.fn(async () => null),runLocationSchedule: vi.fn()}));-vi.mock("../app/modules/production/production.service", async (importOriginal) => ({- ...(await importOriginal<object>()),- // The SQL numbering and receipt need a database;- // serial-number-timing.test.ts covers them.- numberSerialUnitsForCompletion: vi.fn(async () => ({ numbered: 0 })),- completeJobToInventory: vi.fn(async () => {})-}));-import { completeJobToInventory } from "../app/modules/production/production.service";import {closeJob,- completeJob,createProductionQuantity,pauseJob,reopenJob,@@ -82,9 +73,7 @@ const contextWith = (caller: unknown) =>company: { id: "c1", groupId: "g1" },caller: caller as never,system: () => ({}) as never,- // An open transaction: ctx.transaction joins it, and the service- // functions that would use it are stubbed above.- pg: () => ({ isTransaction: true }) as never,+ pg: () => ({}) as never,kv: () => ({}) as never});@@ -220,31 +209,6 @@ describe("closeJob", () => {});});-describe("completeJob", () => {- const complete = (caller: unknown) =>- completeJob(contextWith(caller), { jobId: "j1", quantityComplete: 5 });-- it("returns the database's refusal as a rule", async () => {- vi.mocked(completeJobToInventory).mockRejectedValueOnce(- new Error("Quantity is below what was received")- );- const result = await complete(callerWith(null));- expect(result.error).toMatchObject({- category: "rule",- message: "Quantity is below what was received"- });- });-- it("keeps the completion and warns when returning picked material fails", async () => {- // The sweep posts through `pg`, which this context lacks.- const result = await complete(callerWith(null));- expect(result).toEqual({- data: { jobId: "j1", warning: expect.any(String) },- error: null- });- });-});-describe("createProductionQuantity", () => {const record = (jobStatus: string, type: "Production" | "Scrap") =>createProductionQuantity(diff --git a/apps/erp/test/release-jobs.test.ts b/apps/erp/test/release-jobs.test.tsindex 3741e7b3f3..bc148b39fa 100644--- a/apps/erp/test/release-jobs.test.ts+++ b/apps/erp/test/release-jobs.test.ts@@ -44,11 +44,9 @@ vi.mock("@carbon/jobs", () => ({}));vi.mock("@carbon/lib/workflows", () => ({ raiseMoment: vi.fn() }));vi.mock("@carbon/lib/telemetry", () => ({ trackWorkEvent: vi.fn() }));-// The readiness read has its own test (job-release-readiness); release-// numbering needs a database, and serial-number-timing.test.ts covers it.+// The readiness read has its own test (job-release-readiness).vi.mock("../app/modules/production/production.service", async (importOriginal) => ({...(await importOriginal<object>()),- assignJobSerialNumbersAtRelease: vi.fn(async () => {}),getJobReleaseReadiness: vi.fn()}));