Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.3 KB
Raw Blame
import mongoose from 'mongoose';
import { MongoMemoryServer } from 'mongodb-memory-server';
import { createMCPAuthorityLookupIndexes } from './mcpAuthorityIndexes';

let mongoServer: InstanceType<typeof MongoMemoryServer>;

beforeAll(async () => {
  mongoServer = await MongoMemoryServer.create();
  await mongoose.connect(mongoServer.getUri());
});

afterAll(async () => {
  await mongoose.disconnect();
  await mongoServer.stop();
});

beforeEach(async () => {
  await mongoose.connection.dropDatabase();
});

test('creates every bounded MCP authority lookup index idempotently', async () => {
  const expected = [
    ['groups', 'memberIds_1_tenantId_1'],
    ['agents', 'mcpServerNames_1_tenantId_1'],
    ['pluginauths', 'userId_1_pluginKey_1_authField_1_tenantId_1'],
    ['tokens', 'userId_1_type_1_identifier_1_tenantId_1'],
  ] as const;

  await expect(createMCPAuthorityLookupIndexes(mongoose.connection)).resolves.toEqual(
    expected.map(([, name]) => name),
  );
  await expect(createMCPAuthorityLookupIndexes(mongoose.connection)).resolves.toEqual(
    expected.map(([, name]) => name),
  );
  await Promise.all(
    expected.map(async ([collection, name]) => {
      expect(await mongoose.connection.db!.collection(collection).indexExists(name)).toBe(true);
    }),
  );
});