Update streamableHttp custom fetch test

This commit is contained in:
Cliff Hall 2025-07-01 13:20:28 -04:00
commit e5167cbe20

View file

@ -262,6 +262,36 @@ describe("SSEClientTransport", () => {
expect(lastServerRequest.headers.authorization).toBe(authToken);
});
it("uses custom fetch implementation from options", async () => {
const authToken = "Bearer custom-token";
const fetchWithAuth = jest.fn((url: string | URL, init?: RequestInit) => {
const headers = new Headers(init?.headers);
headers.set("Authorization", authToken);
return fetch(url.toString(), { ...init, headers });
});
transport = new SSEClientTransport(resourceBaseUrl, {
fetch: fetchWithAuth,
});
await transport.start();
expect(lastServerRequest.headers.authorization).toBe(authToken);
// Send a message to verify fetchWithAuth used for POST as well
const message: JSONRPCMessage = {
jsonrpc: "2.0",
id: "1",
method: "test",
params: {},
};
await transport.send(message);
expect(fetchWithAuth).toHaveBeenCalled();
});
it("passes custom headers to fetch requests", async () => {
const customHeaders = {
Authorization: "Bearer test-token",