import { randomUUID } from 'node:crypto'; import type { IdentityApp } from './identity-app'; import { seedProduct } from './commerce'; const auth = { type: 'bearer' as const }; export async function seedActiveBom(ctx: IdentityApp) { const { variant } = await seedProduct(ctx); const material = await ctx .api() .post('/api/v1/materials') .auth(ctx.token, auth) .send({ code: `W-${randomUUID().slice(0, 8)}`, name: 'Soy Wax', kind: 'WAX', unit: 'GRAM', }) .expect(201); const bom = await ctx .api() .post(`/api/v1/variants/${variant.id}/boms`) .auth(ctx.token, auth) .send({ outputQuantity: 10, lines: [{ materialId: material.body.id, quantity: '125.000' }], }) .expect(201); await ctx .api() .post(`/api/v1/boms/${bom.body.id}/activate`) .auth(ctx.token, auth) .expect(201); return { bomId: bom.body.id as string, bomLineId: bom.body.lines[0].id as string, materialId: material.body.id as string, variantId: variant.id as string, }; } export function createBatch( ctx: IdentityApp, bomId: string, plannedQuantity = 20, ) { return ctx .api() .post('/api/v1/production-batches') .auth(ctx.token, auth) .send({ bomId, plannedQuantity, reference: `B-${randomUUID().slice(0, 8)}`, }); }