import { findAgents } from "../agents.getters"; import { setDb } from "../../index"; import { Db, Collection } from "mongodb"; import { createAgent } from "../../../test-utils/factories"; describe("agents getters", () => { let mockDb: Partial; let mockCollection: Partial; beforeEach(() => { const mockAgent = createAgent({ name: "Agent Smith" }); mockCollection = { find: jest.fn().mockReturnValue({ toArray: jest.fn().mockResolvedValue([mockAgent]), }), }; mockDb = { collection: jest.fn().mockReturnValue(mockCollection), }; setDb(mockDb as Db); }); it("findAgents should return agents", async () => { const result = await findAgents(); expect(mockDb.collection).toHaveBeenCalledWith("agents"); expect(result[0].name).toBe("Agent Smith"); }); });