forked from Lilly-Protocol/lily-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.test.ts
More file actions
21 lines (19 loc) · 865 Bytes
/
Copy pathmiddleware.test.ts
File metadata and controls
21 lines (19 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { describe, it, expect } from "vitest";
import { middleware } from "./middleware";
import { NextRequest } from "next/server";
describe("middleware", () => {
it("sets x-request-id header on response when missing in request", () => {
const request = new NextRequest(new URL("/", "http://localhost:3000"));
const response = middleware(request);
expect(response.headers.get("x-request-id")).toBeTruthy();
expect(response.headers.get("x-request-id")?.length).toBeGreaterThan(0);
});
it("preserves existing x-request-id from request", () => {
const existingId = "test-request-id-123";
const request = new NextRequest(new URL("/", "http://localhost:3000"), {
headers: { "x-request-id": existingId },
});
const response = middleware(request);
expect(response.headers.get("x-request-id")).toBe(existingId);
});
});