droboticflow/tests/frontend/runs-api.test.mjs

48 lines
1.8 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
function buildRunsQuery(params = {}) {
const query = new URLSearchParams();
if (params.limit) query.set("limit", String(params.limit));
if (params.cursor?.trim()) query.set("cursor", params.cursor.trim());
if (params.status?.trim()) query.set("status", params.status.trim());
if (params.mode?.trim() && params.mode !== "all") query.set("mode", params.mode.trim());
if (params.q?.trim()) query.set("q", params.q.trim());
if (params.projectId?.trim()) query.set("projectId", params.projectId.trim());
if (params.workflowId?.trim()) query.set("workflowId", params.workflowId.trim());
const suffix = query.toString() ? `?${query.toString()}` : "";
return `/api/runs${suffix}`;
}
test("buildRunsQuery serializes mode parameter correctly", () => {
assert.equal(buildRunsQuery({ mode: "production" }), "/api/runs?mode=production");
assert.equal(buildRunsQuery({ mode: "debug" }), "/api/runs?mode=debug");
assert.equal(buildRunsQuery({ mode: "all" }), "/api/runs");
assert.equal(buildRunsQuery({ mode: "" }), "/api/runs");
});
test("buildRunsQuery combines mode with pagination, status, and project filter", () => {
const url = buildRunsQuery({
projectId: "proj-123",
workflowId: "wf-456",
mode: "production",
status: "completed",
limit: 50,
cursor: "cursor-token",
q: "detection",
});
assert.equal(
url,
"/api/runs?limit=50&cursor=cursor-token&status=completed&mode=production&q=detection&projectId=proj-123&workflowId=wf-456",
);
});
test("buildRunsQuery handles empty or whitespace parameters gracefully", () => {
const url = buildRunsQuery({
mode: " debug ",
projectId: " ",
status: "running",
});
assert.equal(url, "/api/runs?status=running&mode=debug");
});