forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrim-name-description.test.ts
More file actions
62 lines (56 loc) · 1.99 KB
/
Copy pathtrim-name-description.test.ts
File metadata and controls
62 lines (56 loc) · 1.99 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
53
54
55
56
57
58
59
60
61
62
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("Trim name and description before validation (issue #83)", () => {
const app = createApp();
beforeEach(() => {
agentsService.reset?.();
});
it("should trim whitespace from name and description before storing", async () => {
const res = await request(app)
.post("/api/v1/agents")
.send({
name: " Padded Agent Name ",
description: " This description has leading and trailing spaces ",
capabilities: ["test"],
});
expect(res.status).toBe(201);
expect(res.body.success).toBe(true);
expect(res.body.data.agent.name).toBe("Padded Agent Name");
expect(res.body.data.agent.description).toBe("This description has leading and trailing spaces");
});
it("should reject whitespace-only name after trimming", async () => {
const res = await request(app)
.post("/api/v1/agents")
.send({
name: " ",
description: "Valid description with enough characters",
capabilities: ["test"],
});
expect(res.status).toBe(400);
expect(res.body.success).toBe(false);
});
it("should reject whitespace-only description after trimming", async () => {
const res = await request(app)
.post("/api/v1/agents")
.send({
name: "Valid Agent",
description: " ",
capabilities: ["test"],
});
expect(res.status).toBe(400);
expect(res.body.success).toBe(false);
});
it("should still accept valid unpadded inputs", async () => {
const res = await request(app)
.post("/api/v1/agents")
.send({
name: "Normal Agent",
description: "A perfectly normal description without padding",
capabilities: ["test"],
});
expect(res.status).toBe(201);
expect(res.body.data.agent.name).toBe("Normal Agent");
});
});