@@ -10,63 +10,59 @@ vi.setConfig({
1010const nominatimAPI = 'https://nominatim.openstreetmap.org' ;
1111
1212describe ( 'MyTimezone' , ( ) => {
13- const tz = new MyTimezone ( {
13+ const myTimezone = new MyTimezone ( {
1414 offline : true ,
1515 } ) ;
16- let formatted_address : string ;
1716
1817 nock ( nominatimAPI )
1918 . get ( '/search' )
20- . query ( queryObject => {
21- formatted_address = queryObject . q as string ;
22- return true ;
19+ . query ( true )
20+ . reply ( function ( ) {
21+ const parsedURL = new URL ( this . req . path , 'http://example.com' ) ;
22+ const formattedAddress = parsedURL . searchParams . get ( 'q' ) ;
23+
24+ return [
25+ 200 ,
26+ [
27+ {
28+ boundingbox : [ '52.3570365' , '52.6770365' , '13.2288599' , '13.5488599' ] ,
29+ class : 'place' ,
30+ display_name : formattedAddress ,
31+ icon : 'https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png' ,
32+ importance : 1.007539028249136 ,
33+ lat : '52.5170365' ,
34+ licence : 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright' ,
35+ lon : '13.3888599' ,
36+ osm_id : 240109189 ,
37+ osm_type : 'node' ,
38+ place_id : 595794 ,
39+ type : 'city' ,
40+ } ,
41+ ] ,
42+ ] ;
2343 } )
24- . reply ( ( ) => [
25- 200 ,
26- [
27- {
28- boundingbox : [ '52.3570365' , '52.6770365' , '13.2288599' , '13.5488599' ] ,
29- class : 'place' ,
30- display_name : formatted_address ,
31- icon : 'https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png' ,
32- importance : 1.007539028249136 ,
33- lat : '52.5170365' ,
34- licence : 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright' ,
35- lon : '13.3888599' ,
36- osm_id : 240109189 ,
37- osm_type : 'node' ,
38- place_id : 595794 ,
39- type : 'city' ,
40- } ,
41- ] ,
42- ] )
4344 . persist ( ) ;
4445
4546 test ( 'returns an address from Nominatim' , async ( ) => {
4647 const location = 'Berlin, Germany' ;
4748
48- const { formattedAddress} = await tz . getLocationByName ( location ) ;
49+ const { formattedAddress} = await myTimezone . getLocationByName ( location ) ;
4950
5051 expect ( formattedAddress ) . toBe ( location ) ;
5152 } ) ;
5253
5354 test ( 'returns the correct time for a location' , async ( ) => {
54- const berlinTime = await tz . getDateByLongitude ( 13.40803 ) ;
55- //console.log('Timezone at 52.51848, 13.40803:', berlinTime.toString());
56-
57- const frankfurtTime = await tz . getDateByLongitude ( 8.67931 ) ;
58- //console.log('Timezone at 50.11796, 8.67931:', frankfurtTime.toString());
55+ const berlinTime = await myTimezone . getDateByLongitude ( 13.40803 ) ;
56+ const frankfurtTime = await myTimezone . getDateByLongitude ( 8.67931 ) ;
5957
6058 expect ( frankfurtTime . getTime ( ) < berlinTime . getTime ( ) ) . toBe ( true ) ;
6159 } ) ;
6260
6361 test ( 'returns the time for an address' , async ( ) => {
64- const dataBerlin = await tz . getDateByAddress ( 'Berlin, Germany' ) ;
62+ const dataBerlin = await myTimezone . getDateByAddress ( 'Berlin, Germany' ) ;
6563 expect ( dataBerlin ) . toBeDefined ( ) ;
66- //console.log('Timezone Berlin:', dataBerlin.toString());
6764
68- const dataMinsk = await tz . getDateByAddress ( 'Minsk, Belarus' ) ;
65+ const dataMinsk = await myTimezone . getDateByAddress ( 'Minsk, Belarus' ) ;
6966 expect ( dataMinsk ) . toBeDefined ( ) ;
70- //console.log('Timezone Minsk:', dataMinsk.toString());
7167 } ) ;
7268} ) ;
0 commit comments