@@ -14,7 +14,7 @@ const __filename = fileURLToPath(import.meta.url)
14
14
const __dirname = path . dirname ( __filename ) // eslint-disable-line no-unused-vars
15
15
const intersectsGeometry = fs . readFileSync ( path . resolve ( __dirname , '../fixtures/stac/intersectsGeometry.json' ) , 'utf8' )
16
16
17
- // const fixture = (filepath) => fs.readFileSync(path.resolve(__dirname, filepath), 'utf8')
17
+ const fixture = ( filepath ) => fs . readFileSync ( path . resolve ( __dirname , filepath ) , 'utf8' )
18
18
19
19
const ingestEntities = async ( fixtures ) => {
20
20
await ingestItems (
@@ -420,68 +420,92 @@ test('/search preserve intersects geometry in next link', async (t) => {
420
420
t . deepEqual ( nextLink . body . intersects , intersectsGeometry )
421
421
} )
422
422
423
- // test('POST /search using bad geometry, expecting useful error messages', async (t) => {
424
- // let response = null
425
-
426
- // response = await t.context.api.client.post('search', {
427
- // json: {
428
- // intersects: fixture('../fixtures/geometry/badGeoUnclosed.json')
429
- // }
430
- // })
431
- // t.is(response.statusCode, 400)
432
- // t.deepEqual(response.body,
433
- // [{ message: 'the first and last positions in a LinearRing of coordinates must be the same' }])
434
-
435
- // response = await t.context.api.client.post('search', {
436
- // json: {
437
- // intersects: fixture('../fixtures/geometry/badGeoRightHandRule.json')
438
- // }
439
- // })
440
- // t.is(response.statusCode, 400)
441
- // t.deepEqual(response.body,
442
- // [{ message: 'Polygons and MultiPolygons should follow the right-hand rule' }])
443
-
444
- // response = await t.context.api.client.post('search', {
445
- // json: {
446
- // intersects: fixture('../fixtures/geometry/badGeoFourPoints.json')
447
- // }
448
- // })
449
- // t.is(response.statusCode, 400)
450
- // t.deepEqual(response.body, [
451
- // {
452
- // reason: 'failed to create query: at least 4 polygon points required'
453
- // },
454
- // {
455
- // reason: 'failed to create query: at least 4 polygon points required'
456
- // }
457
- // ])
458
-
459
- // response = await t.context.api.client.post('search', {
460
- // json: {
461
- // intersects: fixture('../fixtures/geometry/badGeoDuplicateConsecutive.json')
462
- // }
463
- // })
464
- // t.is(response.statusCode, 400)
465
- // t.deepEqual(response.body, [
466
- // {
467
- // reason: 'failed to create query:
468
- // Provided shape has duplicate consecutive coordinates at: (POINT (100.0 1.0))'
469
- // },
470
- // {
471
- // reason: 'failed to create query:
472
- // Provided shape has duplicate consecutive coordinates at: (POINT (100.0 1.0))'
473
- // }
474
- // ])
475
-
476
- // response = await t.context.api.client.post('search', {
477
- // json: {
478
- // intersects: fixture('../fixtures/geometry/badGeoRightHandRule2.json')
479
- // }
480
- // })
481
- // t.is(response.statusCode, 400)
482
- // t.deepEqual(response.body,
483
- // [{ message: 'Polygons and MultiPolygons should follow the right-hand rule' }])
484
- // })
423
+ test ( 'POST /search - polygon wound incorrectly, but should succeeed' , async ( t ) => {
424
+ const response = await t . context . api . client . post ( 'search' , {
425
+ json : {
426
+ intersects : fixture ( '../fixtures/geometry/polygonWoundCCW.json' )
427
+ }
428
+ } )
429
+ t . is ( response . features . length , 0 )
430
+ } )
431
+
432
+ test ( 'POST /search - failure when polygon is unclosed' , async ( t ) => {
433
+ const error = await t . throwsAsync ( async ( ) => t . context . api . client . post ( 'search' , {
434
+ json : {
435
+ intersects : fixture ( '../fixtures/geometry/badGeoUnclosed.json' )
436
+ }
437
+ } ) )
438
+ t . is ( error . response . statusCode , 400 )
439
+ t . is ( error . response . body . code , 'BadRequest' )
440
+ t . regex ( error . response . body . description ,
441
+ / .* i n v a l i d L i n e a r R i n g f o u n d \( c o o r d i n a t e s a r e n o t c l o s e d \) .* / )
442
+ } )
443
+
444
+ test ( 'POST /search - failure when ambigous winding' , async ( t ) => {
445
+ // The right-hand rule part is ok (see:
446
+ // https://github.com/stac-utils/stac-server/issues/549) but there's
447
+ // coinciding points.
448
+ const error = await t . throwsAsync ( async ( ) => t . context . api . client . post ( 'search' , {
449
+ json : {
450
+ intersects : fixture ( '../fixtures/geometry/badGeoRightHandRule.json' )
451
+ }
452
+ } ) )
453
+ t . is ( error . response . statusCode , 400 )
454
+ t . is ( error . response . body . code , 'BadRequest' )
455
+ t . regex ( error . response . body . description ,
456
+ / .* f a i l e d t o c r e a t e q u e r y : C a n n o t d e t e r m i n e o r i e n t a t i o n : e d g e s a d j a c e n t t o .* / )
457
+ } )
458
+
459
+ test ( 'POST /search - failure when ambigous winding 2' , async ( t ) => {
460
+ // The right-hand rule part is ok (see:
461
+ // https://github.com/stac-utils/stac-server/issues/549) but there's
462
+ // coinciding points.
463
+ const error = await t . throwsAsync ( async ( ) => t . context . api . client . post ( 'search' , {
464
+ json : {
465
+ intersects : fixture ( '../fixtures/geometry/badGeoRightHandRule2.json' )
466
+ }
467
+ } ) )
468
+ t . is ( error . response . statusCode , 400 )
469
+ t . is ( error . response . body . code , 'BadRequest' )
470
+ t . regex ( error . response . body . description ,
471
+ / .* f a i l e d t o c r e a t e q u e r y : C a n n o t d e t e r m i n e o r i e n t a t i o n : e d g e s a d j a c e n t t o .* / )
472
+ } )
473
+
474
+ test ( 'POST /search - failure when Polygon only has 4 points ' , async ( t ) => {
475
+ const error = await t . throwsAsync ( async ( ) => t . context . api . client . post ( 'search' , {
476
+ json : {
477
+ intersects : fixture ( '../fixtures/geometry/badGeoFourPoints.json' )
478
+ }
479
+ } ) )
480
+ t . is ( error . response . statusCode , 400 )
481
+ t . is ( error . response . body . code , 'BadRequest' )
482
+ t . regex ( error . response . body . description ,
483
+ / .* f a i l e d t o c r e a t e q u e r y : a t l e a s t 4 p o l y g o n p o i n t s r e q u i r e d .* / )
484
+ } )
485
+
486
+ test ( 'POST /search - failure when shape has duplicate consecutive coordinates' , async ( t ) => {
487
+ const error = await t . throwsAsync ( async ( ) => t . context . api . client . post ( 'search' , {
488
+ json : {
489
+ intersects : fixture ( '../fixtures/geometry/badGeoDuplicateConsecutive.json' )
490
+ }
491
+ } ) )
492
+ t . is ( error . response . statusCode , 400 )
493
+ t . is ( error . response . body . code , 'BadRequest' )
494
+ t . regex ( error . response . body . description ,
495
+ / .* P r o v i d e d s h a p e h a s d u p l i c a t e c o n s e c u t i v e c o o r d i n a t e s a t .* / )
496
+ } )
497
+
498
+ test ( 'POST /search - failure when MultiPolygon has only 4 points' , async ( t ) => {
499
+ const error = await t . throwsAsync ( async ( ) => t . context . api . client . post ( 'search' , {
500
+ json : {
501
+ intersects : fixture ( '../fixtures/geometry/badGeoFourPointsMultiPolygon.json' )
502
+ }
503
+ } ) )
504
+ t . is ( error . response . statusCode , 400 )
505
+ t . is ( error . response . body . code , 'BadRequest' )
506
+ t . regex ( error . response . body . description ,
507
+ / .* f a i l e d t o c r e a t e q u e r y : a t l e a s t 4 p o l y g o n p o i n t s r e q u i r e d .* / )
508
+ } )
485
509
486
510
test ( '/search preserve bbox in prev and next links' , async ( t ) => {
487
511
const bbox = [ - 180 , - 90 , 180 , 90 ]
0 commit comments