clean up tests - remove mockRequestInfo

This commit is contained in:
Konstantin Konstantinov 2025-06-25 16:24:30 +03:00
commit 606c278668
No known key found for this signature in database
6 changed files with 47 additions and 73 deletions

View file

@ -15,19 +15,11 @@ import {
ListResourcesRequestSchema,
ListToolsRequestSchema,
SetLevelRequestSchema,
ErrorCode,
ErrorCode
} from "../types.js";
import { Transport } from "../shared/transport.js";
import { InMemoryTransport } from "../inMemory.js";
import { Client } from "../client/index.js";
import { RequestInfo } from "./types/types.js";
const mockRequestInfo: RequestInfo = {
headers: {
'content-type': 'application/json',
'traceparent': '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01',
},
};
test("should accept latest protocol version", async () => {
let sendPromiseResolve: (value: unknown) => void;
@ -86,7 +78,7 @@ test("should accept latest protocol version", async () => {
version: "1.0",
},
},
}, { requestInfo: mockRequestInfo });
});
await expect(sendPromise).resolves.toBeUndefined();
});
@ -147,7 +139,7 @@ test("should accept supported older protocol version", async () => {
version: "1.0",
},
},
}, { requestInfo: mockRequestInfo });
});
await expect(sendPromise).resolves.toBeUndefined();
});
@ -207,7 +199,7 @@ test("should handle unsupported protocol version", async () => {
version: "1.0",
},
},
}, { requestInfo: mockRequestInfo });
});
await expect(sendPromise).resolves.toBeUndefined();
});

View file

@ -14,21 +14,13 @@ import {
LoggingMessageNotificationSchema,
Notification,
TextContent,
ElicitRequestSchema,
ElicitRequestSchema
} from "../types.js";
import { ResourceTemplate } from "./mcp.js";
import { completable } from "./completable.js";
import { UriTemplate } from "../shared/uriTemplate.js";
import { RequestInfo } from "./types/types.js";
import { getDisplayName } from "../shared/metadataUtils.js";
const mockRequestInfo: RequestInfo = {
headers: {
'content-type': 'application/json',
'accept': 'application/json',
},
};
describe("McpServer", () => {
/***
* Test: Basic Server Instance
@ -222,8 +214,7 @@ describe("ResourceTemplate", () => {
signal: abortController.signal,
requestId: 'not-implemented',
sendRequest: () => { throw new Error("Not implemented") },
sendNotification: () => { throw new Error("Not implemented") },
requestInfo: mockRequestInfo
sendNotification: () => { throw new Error("Not implemented") }
});
expect(result?.resources).toHaveLength(1);
expect(list).toHaveBeenCalled();

View file

@ -232,7 +232,7 @@ describe('SSEServerTransport', () => {
);
});
/***
/**
* Test: Tool With Request Info
*/
it("should pass request info to tool callback", async () => {

View file

@ -1,11 +1,10 @@
import { randomUUID } from "node:crypto";
import { IncomingMessage, ServerResponse } from "node:http";
import { Transport } from "../shared/transport.js";
import { JSONRPCMessage, JSONRPCMessageSchema } from "../types.js";
import { JSONRPCMessage, JSONRPCMessageSchema, MessageExtraInfo, RequestInfo } from "../types.js";
import getRawBody from "raw-body";
import contentType from "content-type";
import { AuthInfo } from "./auth/types.js";
import { MessageExtraInfo, RequestInfo } from "./types/types.js";
import { URL } from 'url';
const MAXIMUM_MESSAGE_SIZE = "4mb";

View file

@ -1,11 +1,10 @@
import { IncomingMessage, ServerResponse } from "node:http";
import { Transport } from "../shared/transport.js";
import { isInitializeRequest, isJSONRPCError, isJSONRPCRequest, isJSONRPCResponse, JSONRPCMessage, JSONRPCMessageSchema, RequestId, SUPPORTED_PROTOCOL_VERSIONS, DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from "../types.js";
import { MessageExtraInfo, RequestInfo, isInitializeRequest, isJSONRPCError, isJSONRPCRequest, isJSONRPCResponse, JSONRPCMessage, JSONRPCMessageSchema, RequestId, SUPPORTED_PROTOCOL_VERSIONS, DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from "../types.js";
import getRawBody from "raw-body";
import contentType from "content-type";
import { randomUUID } from "node:crypto";
import { AuthInfo } from "./auth/types.js";
import { MessageExtraInfo, RequestInfo } from "./types/types.js";
const MAXIMUM_MESSAGE_SIZE = "4mb";

View file

@ -1,31 +0,0 @@
import { AuthInfo } from "../auth/types.js";
/**
* Headers that are compatible with both Node.js and the browser.
*/
export type IsomorphicHeaders = Record<string, string | string[] | undefined>;
/**
* Information about the incoming request.
*/
export interface RequestInfo {
/**
* The headers of the request.
*/
headers: IsomorphicHeaders;
}
/**
* Extra information about a message.
*/
export interface MessageExtraInfo {
/**
* The request information.
*/
requestInfo?: RequestInfo;
/**
* The authentication information.
*/
authInfo?: AuthInfo;
}