import assert from "node:assert/strict"; import { InventoryResponseSchema, WorkstationResponseSchema } from "@metis/assets/common"; type Request = (path: string, body?: unknown, origin?: string, token?: string) => Promise; /** Prepara puestos independientes para los ordenadores de los escenarios HTTP. */ export async function prepareProfileHosts( request: Request, companyId: string, assetIds: readonly string[] ) { const current = InventoryResponseSchema.parse( await (await request(`/assets/${companyId}`)).json() ); for (const station of current.workstations) { if (station.values.active && assetIds.some((id) => station.values.assetIds.includes(id))) { const closed = await request(`/assets/${companyId}/workstations/${station.id}/update`, { values: { ...station.values, active: false }, }); assert.equal(closed.status, 200, await closed.clone().text()); } } const hosts = []; for (const assetId of assetIds) { const response = await request(`/assets/${companyId}/workstations`, { values: { name: `Puesto perfiles ${assetId}`, active: true, siteId: null, personId: null, computerAssetId: assetId, assetIds: [assetId], }, }); assert.equal(response.status, 201, await response.clone().text()); hosts.push(WorkstationResponseSchema.parse(await response.json()).workstation); } return hosts; }