Skip to content

Commit 33ba4d1

Browse files
committed
fix tests
1 parent 4c93220 commit 33ba4d1

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

tests/integration/helpers.ts

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,22 @@ export const driverOptions = setupDriverConfig({
2929

3030
export const defaultDriverOptions: DriverOptions = { ...driverOptions };
3131

32-
interface ParameterInfo {
32+
interface Parameter {
3333
name: string;
34-
type: string;
3534
description: string;
3635
required: boolean;
3736
}
3837

38+
interface SingleValueParameter extends Parameter {
39+
type: string;
40+
}
41+
42+
interface AnyOfParameter extends Parameter {
43+
anyOf: { type: string }[];
44+
}
45+
46+
type ParameterInfo = SingleValueParameter | AnyOfParameter;
47+
3948
type ToolInfo = Awaited<ReturnType<Client["listTools"]>>["tools"][number];
4049

4150
export interface IntegrationTest {
@@ -217,18 +226,38 @@ export function getParameters(tool: ToolInfo): ParameterInfo[] {
217226

218227
return Object.entries(tool.inputSchema.properties)
219228
.sort((a, b) => a[0].localeCompare(b[0]))
220-
.map(([key, value]) => {
221-
expect(value).toHaveProperty("type");
229+
.map(([name, value]) => {
222230
expect(value).toHaveProperty("description");
223231

224-
const typedValue = value as { type: string; description: string };
225-
expect(typeof typedValue.type).toBe("string");
226-
expect(typeof typedValue.description).toBe("string");
232+
const description = (value as { description: string }).description;
233+
const required = (tool.inputSchema.required as string[])?.includes(name) ?? false;
234+
expect(typeof description).toBe("string");
235+
236+
if (value && typeof value === "object" && "anyOf" in value) {
237+
const typedOptions = new Array<{ type: string }>();
238+
for (const option of value.anyOf as { type: string }[]) {
239+
expect(option).toHaveProperty("type");
240+
241+
typedOptions.push({ type: option.type });
242+
}
243+
244+
return {
245+
name,
246+
anyOf: typedOptions,
247+
description: description,
248+
required,
249+
};
250+
}
251+
252+
expect(value).toHaveProperty("type");
253+
254+
const type = (value as { type: string }).type;
255+
expect(typeof type).toBe("string");
227256
return {
228-
name: key,
229-
type: typedValue.type,
230-
description: typedValue.description,
231-
required: (tool.inputSchema.required as string[])?.includes(key) ?? false,
257+
name,
258+
type,
259+
description,
260+
required,
232261
};
233262
});
234263
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ describeWithMongoDB("createIndex tool", (integration) => {
1414
validateToolMetadata(integration, "create-index", "Create an index for a collection", [
1515
...databaseCollectionParameters,
1616
{
17-
name: "keys",
18-
type: "object",
19-
description: "The index definition",
17+
name: "definition",
18+
anyOf: [
19+
{
20+
type: "object",
21+
},
22+
{
23+
type: "object",
24+
},
25+
],
26+
description:
27+
"The index definition. Use 'classic' for standard indexes and 'vectorSearch' for vector search indexes",
2028
required: true,
2129
},
2230
{
@@ -32,7 +40,7 @@ describeWithMongoDB("createIndex tool", (integration) => {
3240
{ collection: "bar", database: 123, definition: { type: "classic", keys: { foo: 1 } } },
3341
{ collection: [], database: "test", definition: { type: "classic", keys: { foo: 1 } } },
3442
{ collection: "bar", database: "test", definition: { type: "classic", keys: { foo: 1 } }, name: 123 },
35-
{ collection: "bar", database: "test", definition: { type: "classic", keys: { foo: 1 } }, name: "my-index" },
43+
{ collection: "bar", database: "test", definition: { type: "unknown", keys: { foo: 1 } }, name: "my-index" },
3644
]);
3745

3846
describe("with classic indexes", () => {

0 commit comments

Comments
 (0)