Compare commits

...

2 Commits

Author SHA1 Message Date
sweep-ai[bot] 59169d6c8b feat: Updated packages/core/tsconfig.json 2023-10-28 03:11:24 +00:00
sweep-ai[bot] 94961e8f90 feat: Add tests for SimpleMongoReader 2023-10-28 03:10:33 +00:00
2 changed files with 49 additions and 1 deletions
@@ -0,0 +1,48 @@
import { MongoClient } from "mongodb";
import { SimpleMongoReader } from "../readers/SimpleMongoReader";
describe("SimpleMongoReader", () => {
let mockClient: MongoClient;
let reader: SimpleMongoReader;
beforeEach(() => {
mockClient = new MongoClient("");
reader = new SimpleMongoReader(mockClient);
});
it("should construct correctly", () => {
expect(reader).toBeInstanceOf(SimpleMongoReader);
});
it("should load data correctly", async () => {
const mockDbName = "testDb";
const mockCollectionName = "testCollection";
const mockMaxDocs = 10;
const mockQueryDict = { key: "value" };
const mockQueryOptions = { sort: { key: 1 } };
const mockProjection = { key: 1 };
const mockCursor = {
toArray: jest.fn().mockResolvedValue([{ key: "value" }]),
limit: jest.fn().mockReturnThis(),
project: jest.fn().mockReturnThis(),
};
mockClient.db = jest.fn().mockReturnValue({
collection: jest.fn().mockReturnValue({
find: jest.fn().mockReturnValue(mockCursor),
}),
});
const result = await reader.loadData(
mockDbName,
mockCollectionName,
mockMaxDocs,
mockQueryDict,
mockQueryOptions,
mockProjection
);
expect(result).toEqual([{ text: '{"key":"value"}' }]);
});
});
+1 -1
View File
@@ -3,7 +3,7 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"module": "esnext",
"module": "ES6",
"moduleResolution": "node",
"preserveWatchOutput": true,
"skipLibCheck": true,