combined-memory-mcp
Version:
MCP server for Combined Memory API - AI-powered chat with unlimited context, memory management, voice agents, and 500+ tool integrations
149 lines (148 loc) • 7.17 kB
JavaScript
;
/**
* Test HTTP fetching for OpenAPI specs and overlays
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("@jest/globals");
const http_server_1 = require("../helpers/http-server");
const path_1 = __importDefault(require("path"));
describe('HTTP Fetching Tests', () => {
// Define test server properties
const fixturesPath = 'test/fixtures';
const testPort = 8889;
const testServer = new http_server_1.TestHttpServer(fixturesPath, { port: testPort });
// Keep track of original environment
const originalEnv = Object.assign({}, process.env);
const originalArgv = [...process.argv];
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
// Start the test HTTP server
yield testServer.start();
}));
afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
// Stop the test HTTP server
yield testServer.stop();
// Restore original environment
process.env = originalEnv;
process.argv = originalArgv;
}));
beforeEach(() => {
// Reset modules before each test
globals_1.jest.resetModules();
// Reset environment variables
process.env = Object.assign({}, originalEnv);
process.argv = [...originalArgv];
});
it('should fetch OpenAPI spec via HTTP URL', () => __awaiter(void 0, void 0, void 0, function* () {
// Set config to use HTTP URL for OpenAPI spec
const specUrl = testServer.getFileUrl('petstore-openapi.json');
// Mock config module to use our HTTP URL
globals_1.jest.doMock('../../src/config', () => ({
config: {
specPath: specUrl,
overlayPaths: [],
mcpPort: 8080,
targetApiBaseUrl: undefined,
apiKey: undefined,
securitySchemeName: undefined,
securityCredentials: {},
customHeaders: {},
disableXMcp: false,
filter: {
whitelist: null,
blacklist: [],
},
}
}));
// Import the module with our mock applied
const { getProcessedOpenApi: getProcessedOpenApiWithHttpSpec } = require('../../src/openapiProcessor');
// Fetch and process the OpenAPI spec from HTTP URL
const openApiSpec = yield getProcessedOpenApiWithHttpSpec();
// Verify the spec was loaded correctly
expect(openApiSpec).toBeDefined();
expect(openApiSpec.openapi).toBe('3.0.0');
expect(openApiSpec.info.title).toBe('Petstore API');
expect(openApiSpec.paths).toBeDefined();
expect(openApiSpec.paths["/pets"]).toBeDefined();
expect(openApiSpec.paths["/pets/{petId}"]).toBeDefined();
}));
it('should fetch overlay via HTTP URL', () => __awaiter(void 0, void 0, void 0, function* () {
// Set config to use local spec but HTTP URL for overlay
const localSpecPath = path_1.default.resolve(process.cwd(), 'test/fixtures/petstore-openapi.json');
const overlayUrl = testServer.getFileUrl('petstore-overlay.json');
// Mock config module to use our HTTP URL for overlay
globals_1.jest.doMock('../../src/config', () => ({
config: {
specPath: localSpecPath,
overlayPaths: [overlayUrl],
mcpPort: 8080,
targetApiBaseUrl: undefined,
apiKey: undefined,
securitySchemeName: undefined,
securityCredentials: {},
customHeaders: {},
disableXMcp: false,
filter: {
whitelist: null,
blacklist: [],
},
}
}));
// Import the module with our mock applied
const { getProcessedOpenApi: getProcessedOpenApiWithHttpOverlay } = require('../../src/openapiProcessor');
// Fetch and process the OpenAPI spec with HTTP overlay
const openApiSpec = yield getProcessedOpenApiWithHttpOverlay();
// Verify the overlay was applied correctly
expect(openApiSpec).toBeDefined();
expect(openApiSpec.info.title).toBe('Modified Petstore API');
expect(openApiSpec.paths["/pets"].get.summary).toBe('List all pets with overlay');
// Verify parameter changes from overlay were applied
const petIdParam = openApiSpec.paths["/pets/{petId}"].get.parameters.find((p) => p.name === 'petId' && p.in === 'path');
expect(petIdParam).toBeDefined();
expect(petIdParam.description).toBe('Enhanced pet ID description from overlay');
}));
it('should fetch both spec and overlay via HTTP URL', () => __awaiter(void 0, void 0, void 0, function* () {
// Set config to use HTTP URLs for both spec and overlay
const specUrl = testServer.getFileUrl('petstore-openapi.json');
const overlayUrl = testServer.getFileUrl('petstore-overlay.json');
// Mock config module to use HTTP URLs for both
globals_1.jest.doMock('../../src/config', () => ({
config: {
specPath: specUrl,
overlayPaths: [overlayUrl],
mcpPort: 8080,
targetApiBaseUrl: undefined,
apiKey: undefined,
securitySchemeName: undefined,
securityCredentials: {},
customHeaders: {},
disableXMcp: false,
filter: {
whitelist: null,
blacklist: [],
},
}
}));
// Import the module with our mock applied
const { getProcessedOpenApi: getProcessedOpenApiWithHttpUrls } = require('../../src/openapiProcessor');
// Fetch and process both from HTTP URLs
const openApiSpec = yield getProcessedOpenApiWithHttpUrls();
// Verify both spec loading and overlay application worked
expect(openApiSpec).toBeDefined();
expect(openApiSpec.openapi).toBe('3.0.0');
expect(openApiSpec.info.title).toBe('Modified Petstore API');
expect(openApiSpec.paths["/pets"]).toBeDefined();
expect(openApiSpec.paths["/pets"].get.summary).toBe('List all pets with overlay');
}));
});