import { LookupsService } from "./lookups.service"; describe("LookupsService.searchVehicleKindsList", () => { it("echoes q and returns active Caption matches for typeahead", async () => { const searchActiveByCaption = jest.fn().mockResolvedValue([ { Id: 6645, Caption: "کاميون کشنده ولوو FH12 4*2", IsActive: 1, }, ]); const service = new LookupsService({} as any, {} as any, { countDocuments: jest.fn().mockResolvedValue(10), getLatestSyncedAt: jest.fn().mockResolvedValue(new Date()), findAllPublic: jest.fn().mockResolvedValue([]), searchActiveByCaption, replaceAllFromFanavaran: jest.fn(), } as any); const result = await service.searchVehicleKindsList({ q: "ول", limit: 20 }); expect(result).toEqual({ q: "ول", count: 1, items: [ { Id: 6645, Caption: "کاميون کشنده ولوو FH12 4*2", IsActive: 1, }, ], }); expect(searchActiveByCaption).toHaveBeenCalledWith("ول", 20); }); it("returns empty items for blank q without searching", async () => { const searchActiveByCaption = jest.fn(); const service = new LookupsService({} as any, {} as any, { countDocuments: jest.fn().mockResolvedValue(10), getLatestSyncedAt: jest.fn().mockResolvedValue(new Date()), findAllPublic: jest.fn().mockResolvedValue([]), searchActiveByCaption, replaceAllFromFanavaran: jest.fn(), } as any); await expect(service.searchVehicleKindsList({ q: " " })).resolves.toEqual({ q: "", count: 0, items: [], }); expect(searchActiveByCaption).not.toHaveBeenCalled(); }); });