WFDASH-WEBAPP/e2e/agent-api.spec.ts
SJCoetz 7df7a8850f feat(item-history): add getItemHistory service with 5 PB queries
Co-authored-by: Orca <help@stably.ai>
2026-07-29 14:51:58 +02:00

29 lines
1.1 KiB
TypeScript

import { test, expect } from "./_helpers";
const AGENT_KEY = process.env.E2E_AGENT_API_KEY ?? "";
/**
* The agent REST endpoints require a bearer token and a reachable PocketBase.
* The E2E_AGENT_API_KEY must match the AGENT_API_KEY the dev server is using.
* The dev server reads env at boot — if you change it, restart `npm run dev`.
*/
test.describe("agent API auth", () => {
test.skip(
!AGENT_KEY,
"E2E_AGENT_API_KEY not set — skipping agent-API auth specs"
);
test("orders endpoint returns 401 without a bearer token", async ({ request }) => {
const res = await request.get("/api/v1/orders");
expect(res.status()).toBe(401);
});
test("orders endpoint lists when token is valid", async ({ request }) => {
const res = await request.get("/api/v1/orders?perPage=1", {
headers: { authorization: `Bearer ${AGENT_KEY}` },
});
// 200 if PocketBase is reachable, 500 if it isn't — both are valid signals
// that auth passed and we got past the assertAgentAuth guard.
expect([200, 500]).toContain(res.status());
});
});