forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreject-unknown-keys.test.ts
More file actions
52 lines (47 loc) · 1.59 KB
/
Copy pathreject-unknown-keys.test.ts
File metadata and controls
52 lines (47 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
50
51
52
import { describe, it, expect, beforeEach } from "vitest";
import request from "supertest";
import { createApp } from "../src/app";
import { agentsService } from "../src/modules/agents/agents.service";
describe("Reject unknown keys in agent creation (issue #87)", () => {
const app = createApp();
beforeEach(() => {
agentsService.reset?.();
});
it("should reject payloads with unknown keys", async () => {
const res = await request(app)
.post("/api/v1/agents")
.send({
name: "Strict Agent",
description: "Testing strict schema rejection of unknown keys",
capabilities: ["test"],
admin: true,
});
expect(res.status).toBe(400);
expect(res.body.success).toBe(false);
});
it("should accept valid payloads without unknown keys", async () => {
const res = await request(app)
.post("/api/v1/agents")
.send({
name: "Valid Agent",
description: "Testing that valid payloads still pass strict schema",
capabilities: ["test"],
});
expect(res.status).toBe(201);
expect(res.body.success).toBe(true);
});
it("should include unrecognized keys error in response details", async () => {
const res = await request(app)
.post("/api/v1/agents")
.send({
name: "Extra Fields Agent",
description: "Testing error details for unknown key rejection",
capabilities: ["test"],
secretRole: "superadmin",
injectedFlag: true,
});
expect(res.status).toBe(400);
expect(res.body.success).toBe(false);
expect(res.body.message).toBeDefined();
});
});