Skip to content

Commit b926ebe

Browse files
committed
test: middleware detector
1 parent 719d3c0 commit b926ebe

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/core/middleware.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { describe, expect, it } from "@jest/globals";
2+
import { detectMiddlewareName } from "./middleware";
3+
4+
describe("detectMiddlewareName", () => {
5+
it("should return the middleware name when present", () => {
6+
const code = "const config = { middleware: authMiddleware }";
7+
const result = detectMiddlewareName(code);
8+
expect(result).toBe("authMiddleware");
9+
});
10+
11+
it("should return null when middleware name is not present", () => {
12+
const code = "const config = { handler: requestHandler }";
13+
const result = detectMiddlewareName(code);
14+
expect(result).toBeNull();
15+
});
16+
17+
it("should return null when middleware key is present but no name is provided", () => {
18+
const code = "const config = { middleware: }";
19+
const result = detectMiddlewareName(code);
20+
expect(result).toBeNull();
21+
});
22+
23+
it("should return the correct middleware name when there are multiple properties", () => {
24+
const code = "const config = { handler: requestHandler, middleware: loggingMiddleware, timeout: 5000 }";
25+
const result = detectMiddlewareName(code);
26+
expect(result).toBe("loggingMiddleware");
27+
});
28+
29+
it("should handle code without spacing around the colon", () => {
30+
const code = "const config = { middleware:errorHandler }";
31+
const result = detectMiddlewareName(code);
32+
expect(result).toBe("errorHandler");
33+
});
34+
35+
it("should handle code with different spacing around the colon", () => {
36+
const code = "const config = { middleware: errorHandler }";
37+
const result = detectMiddlewareName(code);
38+
expect(result).toBe("errorHandler");
39+
});
40+
});

0 commit comments

Comments
 (0)