import { expect } from '@playwright/test'; import { MockApi, MOCK, Persona } from '../../api'; import { DATA, PROCESS } from './labels'; export type PlannedOrder = { PlannedOrderId: string; ItemNumber: string; Organization: string; SourceOrganization: string | null; OrderType: string; Quantity: number; DueDay: number; DueDate: string; Status: string; ReleasedDocument: string | null; Schedule: { Day: number; Quantity: number }[] }; /** SCP data recipes (tests/data-recipes/scp) through the MOCK SCP pack: REST facade, /api/scp (internal) and /api/processes. */ export class SCPApi { constructor(public api: MockApi) {} rest(as: Persona, method: string, path: string, data?: unknown) { return this.api.call(as, method, path, data, MOCK.restBase); } async restGet(as: Persona, path: string) { const r = await this.rest(as, 'GET', path); expect(r.status, `GET ${path}`).toBe(200); return r.body as T; } async process(as: Persona, name: string, params: Record = {}) { const p = await this.api.ok(as, 'POST', '/processes', { name, params }); expect(p.status, `${name}: ${p.log}`).toBe('SUCCEEDED'); return p; } /** MOCK-only test hook: simulated ESS durations in minutes per process (SLA-breach scenarios). Cleared by the per-test reset. */ async essDurations(map: Record) { return this.api.ok('supply_planner', 'POST', '/test/ess-durations', map); } /** DR-SCP-SRC-001.count_queries: per-entity counts in the synthetic source system (ZZ scope). */ async sourceCounts() { return (await this.api.ok('supply_planner', 'GET', '/scp/source/counts')).counts as Record; } async collectedCounts() { return (await this.restGet<{ items: { Entity: string; SourceCount: number; CollectedCount: number; Difference: number }[] }>('supply_planner', '/planningCollectedData/counts?scope=ZZ')).items; } async collect(type: 'Targeted' | 'Net Change' = 'Targeted') { return this.process('supply_planner', PROCESS.collect, { sourceSystem: DATA.sourceSystem, collectionType: type, organizations: DATA.orgs, entities: DATA.entities }); } async addSalesOrderLine(qty: number, item: string = DATA.buyItem) { return this.api.ok('supply_planner', 'POST', '/scp/source/salesOrders', { item, qty, day: 10 }); } /** DR-SCP-PLN-001: collected data + plan run (unconstrained supply plan by default). */ async plannedRun(plan: string = DATA.supplyPlan, mode = 'Unconstrained') { await this.collect(); return this.process('supply_planner', PROCESS.runPlan, { plan, mode, refresh: 'Yes' }); } async plannedOrders(plan: string = DATA.supplyPlan, as: Persona = 'supply_planner') { return (await this.restGet<{ items: PlannedOrder[] }>(as, `/supplyPlans/${plan}/plannedOrders`)).items; } }