Skip to content

Commit aa94575

Browse files
committed
Add bing.spec.ts
1 parent 0395890 commit aa94575

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`L.Control.Geocoder.Bing > geocodes Microsoft Way, Redmond 1`] = `
4+
[
5+
[
6+
[
7+
{
8+
"bbox": {
9+
"_northEast": {
10+
"lat": 47.643983179153814,
11+
"lng": -122.12206713944467,
12+
},
13+
"_southWest": {
14+
"lat": 47.63625774401246,
15+
"lng": -122.13735364288299,
16+
},
17+
},
18+
"center": {
19+
"lat": 47.64012046158314,
20+
"lng": -122.12971039116383,
21+
},
22+
"name": "1 Microsoft Way, Redmond, WA 98052",
23+
},
24+
],
25+
],
26+
]
27+
`;

spec/bing.spec.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest';
2+
import { mockFetchRequest } from './mockFetchRequest';
3+
import { Bing } from '../src/geocoders/bing';
4+
import { GeocodingResult } from '../src/geocoders/api';
5+
6+
describe('L.Control.Geocoder.Bing', () => {
7+
afterEach(() => vi.clearAllMocks());
8+
it('geocodes Microsoft Way, Redmond', async () => {
9+
const geocoder = new Bing({ apiKey: '0123xyz' });
10+
const result = await mockFetchRequest(
11+
'https://dev.virtualearth.net/REST/v1/Locations/?query=Microsoft+Way%2C+Redmond&key=0123xyz',
12+
{
13+
authenticationResultCode: 'ValidCredentials',
14+
brandLogoUri: 'http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png',
15+
copyright:
16+
'Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.',
17+
resourceSets: [
18+
{
19+
estimatedTotal: 1,
20+
resources: [
21+
{
22+
__type: 'Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1',
23+
bbox: [
24+
47.636257744012461, -122.13735364288299, 47.643983179153814, -122.12206713944467
25+
],
26+
name: '1 Microsoft Way, Redmond, WA 98052',
27+
point: {
28+
type: 'Point',
29+
coordinates: [47.640120461583138, -122.12971039116383]
30+
},
31+
address: {
32+
addressLine: '1 Microsoft Way',
33+
adminDistrict: 'WA',
34+
adminDistrict2: 'King Co.',
35+
countryRegion: 'United States',
36+
formattedAddress: '1 Microsoft Way, Redmond, WA 98052',
37+
locality: 'Redmond',
38+
postalCode: '98052'
39+
},
40+
confidence: 'High',
41+
entityType: 'Address',
42+
geocodePoints: [
43+
{
44+
type: 'Point',
45+
coordinates: [47.640120461583138, -122.12971039116383],
46+
calculationMethod: 'InterpolationOffset',
47+
usageTypes: ['Display']
48+
},
49+
{
50+
type: 'Point',
51+
coordinates: [47.640144601464272, -122.12976671755314],
52+
calculationMethod: 'Interpolation',
53+
usageTypes: ['Route']
54+
}
55+
],
56+
matchCodes: ['Good']
57+
}
58+
]
59+
}
60+
],
61+
statusCode: 200,
62+
statusDescription: 'OK',
63+
traceId: 'b0b1286504404eafa7e7dad3e749d570'
64+
},
65+
() => geocoder.geocode('Microsoft Way, Redmond')
66+
);
67+
68+
const feature: GeocodingResult = result[0];
69+
expect(feature.name).toBe('1 Microsoft Way, Redmond, WA 98052');
70+
expect(feature.center).toStrictEqual({ lat: 47.64012046158314, lng: -122.12971039116383 });
71+
expect([[result]]).toMatchSnapshot();
72+
});
73+
});

0 commit comments

Comments
 (0)