51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
import { autocompleteAmapPlaces, searchAmapPlaces } from '../../../../src/services/amap/amap.places';
|
|
|
|
describe('AMap places adapter', () => {
|
|
it('converts AMap GCJ POI coordinates back to WGS-84', async () => {
|
|
const client = {
|
|
get: vi.fn().mockResolvedValue({
|
|
status: '1',
|
|
pois: [
|
|
{
|
|
id: 'B000A83M61',
|
|
name: 'Tiananmen',
|
|
address: 'Beijing',
|
|
location: '116.403714,39.910627',
|
|
type: 'scenic',
|
|
},
|
|
],
|
|
}),
|
|
};
|
|
|
|
await expect(searchAmapPlaces(client, '天安门')).resolves.toMatchObject({
|
|
source: 'amap',
|
|
places: [
|
|
{
|
|
google_place_id: null,
|
|
google_ftid: null,
|
|
amap_place_id: 'B000A83M61',
|
|
name: 'Tiananmen',
|
|
lat: expect.closeTo(39.908823, 3),
|
|
lng: expect.closeTo(116.39747, 3),
|
|
source: 'amap',
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it('converts a WGS location bias to AMap longitude-latitude order for input tips', async () => {
|
|
const client = { get: vi.fn().mockResolvedValue({ status: '1', tips: [] }) };
|
|
|
|
await autocompleteAmapPlaces(client, '天安门', 'zh', {
|
|
low: { lat: 39.9, lng: 116.3 },
|
|
high: { lat: 40.0, lng: 116.5 },
|
|
});
|
|
|
|
const params = client.get.mock.calls[0]?.[1] as URLSearchParams;
|
|
expect(client.get).toHaveBeenCalledWith('/v3/assistant/inputtips', expect.any(URLSearchParams));
|
|
expect(params.get('location')).toMatch(/^116\./);
|
|
});
|
|
});
|