@@ -6,23 +6,10 @@ expect.extend({toBeDeepCloseTo});
66
77import { Shape , Mesh } from 'three' ;
88import { TextEncoder } from 'node:util' ;
9+ import { expect , test , beforeEach , describe } from '@jest/globals' ;
910global . TextEncoder = TextEncoder ;
1011
11- let apis = {
12- bounding : {
13- api :'https://api.openstreetmap.org/api/0.6/map?bbox=' ,
14- url : ( left , bottom , right , top ) => {
15- return apis . bounding . api + left + ',' + bottom + ',' + right + ',' + top ;
16- } ,
17- } ,
18- getRelation : {
19- api :'https://api.openstreetmap.org/api/0.6/relation/' ,
20- parameters :'/full' ,
21- url : ( relationId ) => {
22- return apis . getRelation . api + relationId + apis . getRelation . parameters ;
23- } ,
24- } ,
25- } ;
12+ import { apis } from '../src/apis.js' ;
2613global . apis = apis ;
2714
2815import { Building } from '../src/building.js' ;
@@ -55,10 +42,24 @@ const data = `
5542</osm>` ;
5643
5744beforeEach ( ( ) => {
58- fetch . resetMocks ( ) ;
45+ fetchMock . resetMocks ( ) ;
5946 errors = [ ] ;
6047} ) ;
6148
49+ describe . each ( [
50+ [ [ 'way' , - 1 ] , [ '' , { status : 404 } ] , / ^ T h e w a y - 1 w a s n o t f o u n d o n t h e s e r v e r .\n U R L : / ] ,
51+ [ [ 'way' , - 1 ] , [ '' , { status : 410 } ] , / ^ T h e w a y - 1 w a s d e l e t e d .\n U R L : / ] ,
52+ [ [ 'way' , - 1 ] , [ '' , { status : 509 } ] , / ^ H T T P 5 0 9 .\n U R L : / ] ,
53+ [ [ 'relation' , - 1 ] , [ '' , { status : 404 } ] , / ^ T h e r e l a t i o n - 1 w a s n o t f o u n d o n t h e s e r v e r .\n U R L : / ] ,
54+ [ [ 'relation' , - 1 ] , [ '' , { status : 410 } ] , / ^ T h e r e l a t i o n - 1 w a s d e l e t e d .\n U R L : / ] ,
55+ [ [ 'relation' , - 1 ] , [ '' , { status : 509 } ] , / ^ H T T P 5 0 9 .\n U R L : / ] ,
56+ ] ) ( 'Test API error handling' , ( args , response , matcher ) => {
57+ test ( `Test API error for ${ args [ 0 ] } ${ args [ 1 ] } with HTTP ${ response [ 1 ] . status } ` , async ( ) => {
58+ fetch . mockResponses ( response ) ;
59+ await expect ( Building . downloadDataAroundBuilding ( ...args ) ) . rejects . toMatch ( matcher ) ;
60+ } ) ;
61+ } ) ;
62+
6263test ( 'Test Constructor' , async ( ) => {
6364 const bldg = new Building ( '31361386' , data ) ;
6465 expect ( bldg . home ) . toBeDeepCloseTo ( [ 11.015512 , 49.5833659 ] , 10 ) ;
0 commit comments