Files
next-tjwater-agent/tests/serverApi/gateway.test.ts
T

54 lines
1.7 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { ServerApiGateway } from "../../src/serverApi/gateway.js";
const context = {
actorKey: "user",
clientSessionId: "session",
projectId: "1c60fd8c-89fb-47ca-84f1-66ec10f5bf73",
projectKey: "project",
sessionId: "runtime",
traceId: "trace",
};
describe("ServerApiGateway project context", () => {
test("uses the metadata path and accepts project_id responses", async () => {
let requestedPath = "";
const fetchImpl = (async (input: URL | RequestInfo) => {
requestedPath = new URL(input.toString()).pathname;
return Response.json({
project_id: context.projectId,
code: "lingang",
name: "临港排水",
description: null,
status: "active",
project_role: "owner",
gs_workspace: "lingang",
map_extent: { xmin: 120.0, ymin: 30.0, xmax: 122.0, ymax: 32.0 },
});
}) as typeof fetch;
const gateway = new ServerApiGateway({} as never, fetchImpl);
const result = await gateway.execute("get_project_context", {}, context);
expect(requestedPath).toBe("/api/v1/meta/project");
expect(result).toMatchObject({
ok: true,
data: { project_id: context.projectId, status: "active", project_role: "owner" },
});
});
test("rejects the removed id response shape", async () => {
const fetchImpl = (async () =>
Response.json({ id: context.projectId, code: "lingang", name: "临港排水" })) as unknown as typeof fetch;
const gateway = new ServerApiGateway({} as never, fetchImpl);
const result = await gateway.execute("get_project_context", {}, context);
expect(result).toMatchObject({
ok: false,
error: { code: "UPSTREAM_UNAVAILABLE" },
});
});
});