Skip to content

Commit e9cef48

Browse files
committed
add more tests
1 parent 2cfc858 commit e9cef48

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

tests/integration/tools/mongodb/create/createIndex.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describeWithMongoDB(
120120
name: "definition",
121121
type: "array",
122122
description:
123-
"The index definition. Use 'classic' for standard indexes and 'vectorSearch' for vector search indexes",
123+
"The index definition. Use 'classic' for standard indexes, 'vectorSearch' for vector search indexes, and 'search' for Atlas Search (lexical) indexes.",
124124
required: true,
125125
},
126126
{

tests/integration/tools/mongodb/delete/dropIndex.test.ts

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ function setupForClassicIndexes(integration: MongoDBIntegrationTestCase): {
5353

5454
function setupForVectorSearchIndexes(integration: MongoDBIntegrationTestCase): {
5555
getMoviesCollection: () => Collection;
56-
getIndexName: () => string;
56+
getSearchIndexName: () => string;
57+
getVectorIndexName: () => string;
5758
} {
5859
let moviesCollection: Collection;
5960
const indexName = "searchIdx";
61+
const vectorIndexName = "vectorIdx";
6062
beforeEach(async () => {
6163
await integration.connectMcpClient();
6264
const mongoClient = integration.mongoClient();
@@ -65,14 +67,24 @@ function setupForVectorSearchIndexes(integration: MongoDBIntegrationTestCase): {
6567
{
6668
name: "Movie1",
6769
plot: "This is a horrible movie about a database called BongoDB and how it tried to copy the OG MangoDB.",
70+
embeddings: [0.1, 0.2, 0.3, 0.4],
6871
},
6972
]);
7073
await waitUntilSearchIsReady(mongoClient);
7174
await moviesCollection.createSearchIndex({
7275
name: indexName,
73-
definition: { mappings: { dynamic: true } },
76+
definition: { mappings: { fields: { plot: { type: "string" } } } },
77+
type: "search",
78+
});
79+
await moviesCollection.createSearchIndex({
80+
name: vectorIndexName,
81+
definition: {
82+
fields: [{ path: "embeddings", type: "vector", numDimensions: 4, similarity: "euclidean" }],
83+
},
84+
type: "vectorSearch",
7485
});
7586
await waitUntilSearchIndexIsListed(moviesCollection, indexName);
87+
await waitUntilSearchIndexIsListed(moviesCollection, vectorIndexName);
7688
});
7789

7890
afterEach(async () => {
@@ -82,7 +94,8 @@ function setupForVectorSearchIndexes(integration: MongoDBIntegrationTestCase): {
8294

8395
return {
8496
getMoviesCollection: () => moviesCollection,
85-
getIndexName: () => indexName,
97+
getSearchIndexName: () => indexName,
98+
getVectorIndexName: () => vectorIndexName,
8699
};
87100
}
88101

@@ -341,7 +354,8 @@ describe.each([{ vectorSearchEnabled: false }, { vectorSearchEnabled: true }])(
341354
describeWithMongoDB(
342355
"when connected to MongoDB with search support",
343356
(integration) => {
344-
const { getIndexName } = setupForVectorSearchIndexes(integration);
357+
const { getSearchIndexName, getVectorIndexName, getMoviesCollection } =
358+
setupForVectorSearchIndexes(integration);
345359

346360
describe.each([
347361
{
@@ -362,35 +376,39 @@ describe.each([{ vectorSearchEnabled: false }, { vectorSearchEnabled: true }])(
362376
collection: "movies",
363377
indexName: "non-existent-index",
364378
},
365-
])(
366-
"and attempting to delete $title (namespace - $database $collection)",
367-
({ database, collection, indexName }) => {
368-
it("should fail with appropriate error", async () => {
369-
const response = await integration.mcpClient().callTool({
370-
name: "drop-index",
371-
arguments: { database, collection, indexName, type: "search" },
372-
});
373-
expect(response.isError).toBe(true);
374-
const content = getResponseContent(response.content);
375-
expect(content).toContain("Index does not exist in the provided namespace.");
379+
])("and attempting to delete $title", ({ database, collection, indexName }) => {
380+
it("should fail with appropriate error", async () => {
381+
const response = await integration.mcpClient().callTool({
382+
name: "drop-index",
383+
arguments: { database, collection, indexName, type: "search" },
384+
});
385+
expect(response.isError).toBe(true);
386+
const content = getResponseContent(response.content);
387+
expect(content).toContain("Index does not exist in the provided namespace.");
376388

377-
const data = getDataFromUntrustedContent(content);
378-
expect(JSON.parse(data)).toMatchObject({
379-
indexName,
380-
namespace: `${database}.${collection}`,
381-
});
389+
const data = getDataFromUntrustedContent(content);
390+
expect(JSON.parse(data)).toMatchObject({
391+
indexName,
392+
namespace: `${database}.${collection}`,
382393
});
383-
}
384-
);
394+
});
395+
});
385396

386-
describe("and attempting to delete an existing index", () => {
397+
describe.each([
398+
{ description: "search", indexName: getSearchIndexName() },
399+
{ description: "vector search", indexName: getVectorIndexName() },
400+
])("and attempting to delete an existing $description index", ({ indexName }) => {
387401
it("should succeed in deleting the index", async () => {
402+
const collection = getMoviesCollection();
403+
let indexes = await collection.listSearchIndexes().toArray();
404+
expect(indexes.find((idx) => idx.name === indexName)).toBeDefined();
405+
388406
const response = await integration.mcpClient().callTool({
389407
name: "drop-index",
390408
arguments: {
391-
database: "mflix",
392-
collection: "movies",
393-
indexName: getIndexName(),
409+
database: collection.dbName,
410+
collection: collection.collectionName,
411+
indexName,
394412
type: "search",
395413
},
396414
});
@@ -401,9 +419,12 @@ describe.each([{ vectorSearchEnabled: false }, { vectorSearchEnabled: true }])(
401419

402420
const data = getDataFromUntrustedContent(content);
403421
expect(JSON.parse(data)).toMatchObject({
404-
indexName: getIndexName(),
422+
indexName,
405423
namespace: "mflix.movies",
406424
});
425+
426+
indexes = await collection.listSearchIndexes().toArray();
427+
expect(indexes.find((idx) => idx.name === indexName)).toBeUndefined();
407428
});
408429
});
409430
},
@@ -417,7 +438,7 @@ describe.each([{ vectorSearchEnabled: false }, { vectorSearchEnabled: true }])(
417438
describeWithMongoDB(
418439
"when invoked via an elicitation enabled client",
419440
(integration) => {
420-
const { getIndexName } = setupForVectorSearchIndexes(integration);
441+
const { getSearchIndexName: getIndexName } = setupForVectorSearchIndexes(integration);
421442
let dropSearchIndexSpy: MockInstance;
422443

423444
beforeEach(() => {

0 commit comments

Comments
 (0)