Files
Compass/backend/api/tests/unit/search-location.unit.test.ts
2026-01-15 16:54:29 +01:00

36 lines
1.2 KiB
TypeScript

jest.mock('common/geodb');
import { AuthedUser } from "api/helpers/endpoint";
import { searchLocation } from "api/search-location";
import * as geodbModules from "common/geodb";
describe('searchLocation', () => {
beforeEach(() => {
jest.resetAllMocks();
});
afterEach(() => {
jest.restoreAllMocks();
});
describe('when given valid input', () => {
it('should return search location', async () => {
const mockBody = {
term: "mockTerm",
limit: 15
};
const mockAuth = { uid: '321' } as AuthedUser;
const mockReq = {} as any;
const mockReturn = "Pass";
(geodbModules.geodbFetch as jest.Mock).mockResolvedValue(mockReturn);
const result = await searchLocation(mockBody, mockAuth, mockReq);
expect(result).toBe(mockReturn);
expect(geodbModules.geodbFetch).toBeCalledTimes(1);
expect(geodbModules.geodbFetch).toBeCalledWith(
expect.stringContaining(`/cities?namePrefix=${mockBody.term}&limit=${mockBody.limit}&offset=0&sort=-population`)
);
});
});
});