forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-prefixed-404.test.ts
More file actions
33 lines (29 loc) · 1.3 KB
/
Copy pathapi-prefixed-404.test.ts
File metadata and controls
33 lines (29 loc) · 1.3 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
import { describe, it, expect } from "vitest";
import request from "supertest";
import { createApp } from "../src/app";
describe("API-prefixed 404 handler (issue #132)", () => {
const app = createApp();
it("should return 404 with envelope for unknown path under /api/v1", async () => {
const res = await request(app).get("/api/v1/nope");
expect(res.status).toBe(404);
expect(res.body.success).toBe(false);
expect(res.body.message).toContain("Route not found");
expect(res.body.message).toContain("GET");
expect(res.body.message).toContain("/api/v1/nope");
});
it("should return 404 with envelope for unknown path outside prefix", async () => {
const res = await request(app).get("/missing");
expect(res.status).toBe(404);
expect(res.body.success).toBe(false);
expect(res.body.message).toContain("Route not found");
expect(res.body.message).toContain("GET");
expect(res.body.message).toContain("/missing");
});
it("should include method and path in 404 message for POST under prefix", async () => {
const res = await request(app).post("/api/v1/unknown-endpoint");
expect(res.status).toBe(404);
expect(res.body.success).toBe(false);
expect(res.body.message).toContain("POST");
expect(res.body.message).toContain("/api/v1/unknown-endpoint");
});
});