forked from Yara724/api
lookup vehicle-kinds added
This commit is contained in:
54
src/lookups/lookups.service.vehicle-list.spec.ts
Normal file
54
src/lookups/lookups.service.vehicle-list.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user