Skip to content

Commit 68f3572

Browse files
committed
fix tests
1 parent 60e178c commit 68f3572

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

tests/integration/resources/exportedData.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import path from "path";
22
import fs from "fs/promises";
3-
import type { ObjectId } from "bson";
4-
import { EJSON, Long } from "bson";
3+
import { EJSON, Long, ObjectId } from "bson";
54
import { describe, expect, it, beforeEach, afterAll } from "vitest";
65
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
76
import { defaultTestConfig, getDataFromUntrustedContent, resourceChangedNotification, timeout } from "../helpers.js";
@@ -16,17 +15,20 @@ const userConfig: UserConfig = {
1615
exportCleanupIntervalMs: 300,
1716
};
1817

19-
const docs = [
20-
{ name: "foo", longNumber: new Long(1234) },
21-
{ name: "bar", bigInt: new Long(123412341234) },
22-
];
23-
2418
describeWithMongoDB(
2519
"exported-data resource",
2620
(integration) => {
21+
let docs: { _id: ObjectId; name: string; longNumber?: Long; bigInt?: Long }[];
22+
let collection: string;
23+
2724
beforeEach(async () => {
2825
const mongoClient = integration.mongoClient();
29-
await mongoClient.db("db").collection("coll").insertMany(docs);
26+
collection = new ObjectId().toString();
27+
docs = [
28+
{ name: "foo", longNumber: new Long(1234), _id: new ObjectId() },
29+
{ name: "bar", bigInt: new Long(123412341234), _id: new ObjectId() },
30+
];
31+
await mongoClient.db("db").collection(collection).insertMany(docs);
3032
});
3133

3234
afterAll(async () => {
@@ -67,7 +69,7 @@ describeWithMongoDB(
6769
name: "export",
6870
arguments: {
6971
database: "db",
70-
collection: "coll",
72+
collection,
7173
exportTitle: "Export for db.coll",
7274
exportTarget: [{ name: "find", arguments: {} }],
7375
},
@@ -106,7 +108,7 @@ describeWithMongoDB(
106108
name: "export",
107109
arguments: {
108110
database: "db",
109-
collection: "coll",
111+
collection,
110112
exportTitle: "Export for db.coll",
111113
exportTarget: [{ name: "find", arguments: {} }],
112114
},
@@ -143,7 +145,7 @@ describeWithMongoDB(
143145
name: "export",
144146
arguments: {
145147
database: "big",
146-
collection: "coll",
148+
collection,
147149
exportTitle: "Export for big.coll",
148150
exportTarget: [{ name: "find", arguments: {} }],
149151
},

tests/unit/common/exportsManager.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ describe("ExportsManager unit test", () => {
235235
jsonExportFormat: "relaxed",
236236
});
237237
await exportAvailableNotifier;
238-
expect(await manager.readExport(exportName)).toEqual("[]");
238+
const { content, docsTransformed } = await manager.readExport(exportName);
239+
expect(content).toEqual("[]");
240+
expect(docsTransformed).toEqual(0);
239241
});
240242

241243
it("should handle encoded name", async () => {
@@ -249,7 +251,9 @@ describe("ExportsManager unit test", () => {
249251
jsonExportFormat: "relaxed",
250252
});
251253
await exportAvailableNotifier;
252-
expect(await manager.readExport(encodeURIComponent(exportName))).toEqual("[]");
254+
const { content, docsTransformed } = await manager.readExport(encodeURIComponent(exportName));
255+
expect(content).toEqual("[]");
256+
expect(docsTransformed).toEqual(0);
253257
});
254258
});
255259

@@ -332,7 +336,7 @@ describe("ExportsManager unit test", () => {
332336
expect(emitSpy).toHaveBeenCalledWith("export-available", exportURI);
333337

334338
// Exports relaxed json
335-
const jsonData = JSON.parse(await manager.readExport(exportName)) as unknown[];
339+
const jsonData = JSON.parse((await manager.readExport(exportName)).content) as unknown[];
336340
expect(jsonData).toEqual([]);
337341
});
338342
});
@@ -366,7 +370,7 @@ describe("ExportsManager unit test", () => {
366370
expect(emitSpy).toHaveBeenCalledWith("export-available", `exported-data://${expectedExportName}`);
367371

368372
// Exports relaxed json
369-
const jsonData = JSON.parse(await manager.readExport(expectedExportName)) as unknown[];
373+
const jsonData = JSON.parse((await manager.readExport(expectedExportName)).content) as unknown[];
370374
expect(jsonData).toContainEqual(expect.objectContaining({ name: "foo", longNumber: 12 }));
371375
expect(jsonData).toContainEqual(expect.objectContaining({ name: "bar", longNumber: 123456 }));
372376
});
@@ -401,7 +405,7 @@ describe("ExportsManager unit test", () => {
401405
expect(emitSpy).toHaveBeenCalledWith("export-available", `exported-data://${expectedExportName}`);
402406

403407
// Exports relaxed json
404-
const jsonData = JSON.parse(await manager.readExport(expectedExportName)) as unknown[];
408+
const jsonData = JSON.parse((await manager.readExport(expectedExportName)).content) as unknown[];
405409
expect(jsonData).toContainEqual(
406410
expect.objectContaining({ name: "foo", longNumber: { $numberLong: "12" } })
407411
);

0 commit comments

Comments
 (0)