Skip to content

Commit 2a5878d

Browse files
committed
test: Address CodeRabbit review on GeoPoint specs
- Drop the misleading GeoPointLiteral[] | unknown union on withinPolygon (negative-path specs deliberately pass invalid values, so the param is unknown) - Drop the unnecessary masterKey auth in the __type response test - Filter the sub-object and array specs on a sentinel tag instead of an unfiltered find, so they don't depend on global cleanup ordering - Clarify the seed-point comments (inside / on boundary / outside)
1 parent 9c7e77c commit 2a5878d

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

spec/helpers/geo.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ export function withinGeoBox(southwest: GeoPointLiteral, northeast: GeoPointLite
4242
return { $within: { $box: [southwest, northeast] } };
4343
}
4444

45-
/** Search within a polygon, given either a list of points or a Polygon object. */
46-
export function withinPolygon(polygon: GeoPointLiteral[] | unknown) {
45+
/**
46+
* Search within a polygon, given a list of GeoPoints or a Polygon object.
47+
* Typed as `unknown` because the negative-path specs deliberately pass invalid
48+
* values (numbers, empty arrays, malformed points) to exercise server validation.
49+
*/
50+
export function withinPolygon(polygon: unknown) {
4751
return { $geoWithin: { $polygon: polygon } };
4852
}
4953

spec/rest/objects/geopoint-polygon.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { ParseError } from '../../helpers/errors.ts';
77

88
function seedPolygonPoints() {
99
return createObjects('Polygon', [
10-
{ location: geoPoint(1.5, 1.5) }, // inbound
11-
{ location: geoPoint(10, 10) }, // onbound
12-
{ location: geoPoint(20, 20) }, // outbound
10+
{ location: geoPoint(1.5, 1.5) }, // inside
11+
{ location: geoPoint(10, 10) }, // on boundary
12+
{ location: geoPoint(20, 20) }, // outside
1313
]);
1414
}
1515

spec/rest/objects/geopoint.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('GeoPoint REST', () => {
3030
location: geoPoint(44.0, -11.0),
3131
name: 'Zhoul',
3232
});
33-
const result = await getObject('TestObject', created.objectId, { masterKey: true });
33+
const result = await getObject('TestObject', created.objectId);
3434
expect(result.location.__type).toEqual('GeoPoint');
3535
});
3636

@@ -53,8 +53,11 @@ describe('GeoPoint REST', () => {
5353
});
5454

5555
it('supports a sub-object with a geo point', async () => {
56-
await createObject('TestObject', { subobject: { location: geoPoint(44.0, -11.0) } });
57-
const results = await find('TestObject');
56+
await createObject('TestObject', {
57+
subobject: { location: geoPoint(44.0, -11.0) },
58+
tag: 'subobject-geo',
59+
});
60+
const results = await find('TestObject', { where: { tag: 'subobject-geo' } });
5861
expect(results.length).toEqual(1);
5962
const pointAgain = results[0].subobject.location;
6063
expect(pointAgain).toBeTruthy();
@@ -65,8 +68,8 @@ describe('GeoPoint REST', () => {
6568
it('supports array of geo points', async () => {
6669
const point1 = geoPoint(44.0, -11.0);
6770
const point2 = geoPoint(22.0, -55.0);
68-
await createObject('TestObject', { locations: [point1, point2] });
69-
const results = await find('TestObject');
71+
await createObject('TestObject', { locations: [point1, point2], tag: 'array-geo' });
72+
const results = await find('TestObject', { where: { tag: 'array-geo' } });
7073
expect(results.length).toEqual(1);
7174
const locations = results[0].locations;
7275
expect(locations.length).toEqual(2);

0 commit comments

Comments
 (0)