Files
next-tjwater-frontend/tests/browser/support/mock-scada-api.ts
T
jiang f9c71cc076
Generic Container CI/CD / test-build-publish (push) Successful in 26s
Frontend CI/CD / build-test-publish-and-deploy (push) Successful in 26s
feat(workbench): align v2 GIS and SCADA API
2026-09-08 18:18:40 +08:00

28 lines
930 B
TypeScript

import type { Page } from "@playwright/test";
export async function mockScadaApi(page: Page, devices: unknown[] = []) {
await page.route("https://tjwater-api.invalid/**", async (route) => {
const url = new URL(route.request().url());
if (url.pathname === "/api/v1/projects") {
await route.fulfill({
contentType: "application/json",
body: JSON.stringify({
items: [{ project_id: "project-1", gs_workspace: "tjwater_next", status: "active" }],
total: 1,
limit: 1000,
offset: 0
})
});
return;
}
if (url.pathname === "/api/v1/scada-devices") {
await route.fulfill({
contentType: "application/json",
body: JSON.stringify({ items: devices, total: devices.length, limit: 1000, offset: 0 })
});
return;
}
await route.fulfill({ status: 404, contentType: "application/json", body: "{}" });
});
}