forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuccess-envelope-contract.test.ts
More file actions
49 lines (43 loc) · 1.59 KB
/
Copy pathsuccess-envelope-contract.test.ts
File metadata and controls
49 lines (43 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { describe, it, expect } from "vitest";
import request from "supertest";
import { createApp } from "../src/app";
describe("Success envelope contract (issue #130)", () => {
const app = createApp();
const successEndpoints = [
{ method: "get", path: "/api/v1/health" },
{ method: "get", path: "/api/v1/agents" },
{
method: "post",
path: "/api/v1/agents",
body: {
name: "Envelope Test Agent",
description: "Testing success envelope contract",
capabilities: ["test"],
},
},
];
for (const endpoint of successEndpoints) {
it(`${endpoint.method.toUpperCase()} ${endpoint.path} returns { success: true, data }`, async () => {
const req =
endpoint.method === "post"
? request(app).post(endpoint.path)
: request(app).get(endpoint.path);
if (endpoint.body) {
req.send(endpoint.body);
}
const res = await req;
expect(res.status).toBeGreaterThanOrEqual(200);
expect(res.status).toBeLessThan(300);
expect(res.body).toHaveProperty("success", true);
expect(res.body).toHaveProperty("data");
});
}
it("should have consistent envelope shape across all tested endpoints", async () => {
const healthRes = await request(app).get("/api/v1/health");
const agentsRes = await request(app).get("/api/v1/agents");
expect(Object.keys(healthRes.body)).toContain("success");
expect(Object.keys(healthRes.body)).toContain("data");
expect(Object.keys(agentsRes.body)).toContain("success");
expect(Object.keys(agentsRes.body)).toContain("data");
});
});