Skip to content

Commit 68fc2f7

Browse files
chore: add normal telemetry event tests
1 parent de74005 commit 68fc2f7

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ describeWithMongoDB("insertMany tool when search is disabled", (integration) =>
102102
expect(content).toContain(insertedIds[0]?.toString());
103103
});
104104

105+
it("should emit tool event without auto-embedding usage metadata", async () => {
106+
const mockEmitEvents = vi.spyOn(integration.mcpServer()["telemetry"], "emitEvents");
107+
vi.spyOn(integration.mcpServer()["telemetry"], "isTelemetryEnabled").mockReturnValue(true);
108+
await integration.connectMcpClient();
109+
110+
const response = await integration.mcpClient().callTool({
111+
name: "insert-many",
112+
arguments: {
113+
database: integration.randomDbName(),
114+
collection: "test",
115+
documents: [{ title: "The Matrix" }],
116+
},
117+
});
118+
119+
const content = getResponseContent(response.content);
120+
expect(content).toContain("Documents were inserted successfully.");
121+
122+
expect(mockEmitEvents).toHaveBeenCalled();
123+
const emittedEvent = mockEmitEvents.mock.lastCall?.[0][0] as ToolEvent;
124+
expectDefined(emittedEvent);
125+
expect(emittedEvent.properties.embeddingsGeneratedBy).toBeUndefined();
126+
});
127+
105128
validateAutoConnectBehavior(integration, "insert-many", () => {
106129
return {
107130
args: {

tests/integration/tools/mongodb/read/aggregate.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,36 @@ describeWithMongoDB("aggregate tool", (integration) => {
153153
);
154154
});
155155

156+
it("should emit tool event without auto-embedding usage metadata", async () => {
157+
const mockEmitEvents = vi.spyOn(integration.mcpServer()["telemetry"], "emitEvents");
158+
vi.spyOn(integration.mcpServer()["telemetry"], "isTelemetryEnabled").mockReturnValue(true);
159+
160+
const mongoClient = integration.mongoClient();
161+
await mongoClient
162+
.db(integration.randomDbName())
163+
.collection("people")
164+
.insertMany([
165+
{ name: "Peter", age: 5 },
166+
{ name: "Laura", age: 10 },
167+
{ name: "Søren", age: 15 },
168+
]);
169+
170+
await integration.connectMcpClient();
171+
await integration.mcpClient().callTool({
172+
name: "aggregate",
173+
arguments: {
174+
database: integration.randomDbName(),
175+
collection: "people",
176+
pipeline: [{ $match: { age: { $gt: 8 } } }, { $sort: { name: -1 } }],
177+
},
178+
});
179+
180+
expect(mockEmitEvents).toHaveBeenCalled();
181+
const emittedEvent = mockEmitEvents.mock.lastCall?.[0][0] as ToolEvent;
182+
expectDefined(emittedEvent);
183+
expect(emittedEvent.properties.embeddingsGeneratedBy).toBeUndefined();
184+
});
185+
156186
for (const disabledOpType of ["create", "update", "delete"] as const) {
157187
it(`can not run $out stages when ${disabledOpType} operation is disabled`, async () => {
158188
await integration.connectMcpClient();

0 commit comments

Comments
 (0)