Files
Compass/backend/api/tests/unit/search-location.unit.test.ts
Martin Braquet ba9b3cfb06 Add pretty formatting (#29)
* Test

* Add pretty formatting

* Fix Tests

* Fix Tests

* Fix Tests

* Fix

* Add pretty formatting fix

* Fix

* Test

* Fix tests

* Clean typeckech

* Add prettier check

* Fix api tsconfig

* Fix api tsconfig

* Fix tsconfig

* Fix

* Fix

* Prettier
2026-02-20 17:32:27 +01:00

39 lines
1.0 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`,
),
)
})
})
})