- Implement `current-operating-systems-ui.test.py` to validate the functionality of current operating systems in the UI, including tests for source and states, computer changes, responsive design, error handling, and version saving. - Create `workplace-add-asset.test.py` to test the addition of assets to workstations, covering scenarios such as conflict resolution, responsive design on mobile, error handling during asset creation, and HTTP guards for asset management.
27 lines
808 B
TypeScript
27 lines
808 B
TypeScript
import { csrfFetch } from "@metis/core/client";
|
|
import { z } from "zod/v4";
|
|
|
|
import { InventoryApiError } from "./inventory-api-error";
|
|
|
|
export async function inventoryRequest(
|
|
path: string,
|
|
body?: unknown,
|
|
headers?: Record<string, string>
|
|
) {
|
|
const response = await csrfFetch(`/api/assets/${path}`, {
|
|
method: body === undefined ? "GET" : "POST",
|
|
credentials: "same-origin",
|
|
headers: { ...(body === undefined ? {} : { "content-type": "application/json" }), ...headers },
|
|
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
});
|
|
const data: unknown = await response.json();
|
|
|
|
if (!response.ok) {
|
|
const error = z.object({ code: z.string() }).safeParse(data);
|
|
|
|
throw new InventoryApiError(error.success ? error.data.code : "INTERNAL_ERROR");
|
|
}
|
|
|
|
return data;
|
|
}
|