import { applyQueryOptions } from "../query.utils"; describe("query.utils", () => { describe("applyQueryOptions()", () => { let mockCursor: any; beforeEach(() => { mockCursor = { sort: jest.fn().mockReturnThis(), skip: jest.fn().mockReturnThis(), limit: jest.fn().mockReturnThis(), }; }); it("should return cursor if no options provided", () => { const result = applyQueryOptions(mockCursor); expect(result).toBe(mockCursor); expect(mockCursor.sort).not.toHaveBeenCalled(); }); it("should apply sort, skip, and limit", () => { const options = { sort: { name: 1 }, skip: 10, limit: 5, }; const result = applyQueryOptions(mockCursor, options); expect(result).toBe(mockCursor); expect(mockCursor.sort).toHaveBeenCalledWith({ name: 1 }); expect(mockCursor.skip).toHaveBeenCalledWith(10); expect(mockCursor.limit).toHaveBeenCalledWith(5); }); it("should apply only sort if skip and limit are missing", () => { const options = { sort: { name: 1 }, }; const result = applyQueryOptions(mockCursor, options); expect(result).toBe(mockCursor); expect(mockCursor.sort).toHaveBeenCalledWith({ name: 1 }); expect(mockCursor.skip).not.toHaveBeenCalled(); expect(mockCursor.limit).not.toHaveBeenCalled(); }); }); });