File size: 3,290 Bytes
af1bee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { expect } from '@playwright/test';
import { MockApi, MOCK, Persona } from '../../api';
import { DATA } from './labels';

/** P2M data recipes (tests/data-recipes/p2m) through the MOCK packs: SCM misc receipts (on-hand seed), P2M REST workOrders, /api/p2m. */
export class P2MApi {
  constructor(public api: MockApi) {}
  rest(as: Persona, method: string, path: string, data?: unknown) { return this.api.call(as, method, path, data, MOCK.restBase); }
  async restQ(as: Persona, resource: string, q: string) { const r = await this.rest(as, 'GET', `/${resource}?q=${encodeURIComponent(q)}`); expect(r.status, `GET ${resource}?q=${q}`).toBe(200); return r.body as { items: any[]; count: number }; }
  /** DR-P2M-WO-001: on-hand A 30 / B 15 seeded via SCM misc receipt (SCM-INV-003 pattern) and costed (components at 10.00 / 5.00). */
  async seedComponents(a = 30, b = 15) {
    await this.api.ok('scm_integration', 'POST', '/scm/miscTransactions', { type: 'Miscellaneous Receipt', item: DATA.compA, org: DATA.plantOrg, subinv: DATA.stores, qty: a, unitCost: 10 });
    await this.api.ok('scm_integration', 'POST', '/scm/miscTransactions', { type: 'Miscellaneous Receipt', item: DATA.compB, org: DATA.plantOrg, subinv: DATA.stores, qty: b, unitCost: 5 });
    const p = await this.api.ok('cost_accountant', 'POST', '/processes', { name: 'Create Cost Accounting Distributions', params: { costOrg: 'ZZ Cost Org (MOCK)' } }); expect(p.status).toBe('SUCCEEDED');
  }
  async seedSpares(qty = 10) { await this.api.ok('scm_integration', 'POST', '/scm/miscTransactions', { type: 'Miscellaneous Receipt', item: DATA.seal, org: DATA.plantOrg, subinv: DATA.stores, qty, unitCost: 15 }); }
  /** REST import path (DR-P2M-WO-001.wo_payload). */
  async workOrder(qty: number, as: Persona = 'production_supervisor', org: string = DATA.plantOrg) {
    const r = await this.rest(as, 'POST', '/workOrders', { ItemNumber: DATA.fgItem, PlannedStartQuantity: qty, OrganizationCode: org }); expect(r.status, JSON.stringify(r.body)).toBe(201); return r.body;
  }
  wo(method: string, path: string, data?: unknown) { return this.api.ok('scm_integration', method, `/scm/workOrders${path}`, data); }
  /** WO released (and optionally picked / issued / with op 10 moved) for execution cases. */
  async releasedWo(qty = 10, o: { pick?: boolean } = {}) { const w = await this.workOrder(qty); await this.wo('POST', `/${w.WorkOrderNumber}/release`); if (o.pick) await this.wo('POST', `/${w.WorkOrderNumber}/pick`); return w.WorkOrderNumber as string; }
  async onhand(item: string) { const b = await this.restQ('scm_integration', 'inventoryOnhandBalances', `ItemNumber='${item}';OrganizationCode='${DATA.plantOrg}'`); return b.items as { SubinventoryCode: string; LotNumber: string | null; OnhandQuantity: number }[]; }
  /** DR-P2M-MNT-001: released corrective maintenance WO on the synthetic asset. */
  async releasedMaintWo(start: string) {
    const w = await this.api.ok('maintenance_planner', 'POST', '/p2m/maintenanceWorkOrders', { asset: DATA.asset, type: 'Corrective', description: 'ZZ pump leak (recipe)' });
    await this.api.ok('maintenance_planner', 'POST', `/p2m/maintenanceWorkOrders/${w.number}/release`, { scheduledStart: start }); return w.number as string;
  }
}