diff --git a/spec/ParseGeoPoint.spec.js b/spec/ParseGeoPoint.spec.js index ec6ec79295..54eeac9fa1 100644 --- a/spec/ParseGeoPoint.spec.js +++ b/spec/ParseGeoPoint.spec.js @@ -114,7 +114,7 @@ describe('Parse.GeoPoint testing', () => { const query = new Parse.Query(TestObject); const point = new Parse.GeoPoint(24, 19); query.equalTo('construct', 'line'); - query.withinMiles('location', point, 10000); + query.withinMiles('location', point, 10000, true); query.find({ success: function(results) { equal(results.length, 10); @@ -139,7 +139,7 @@ describe('Parse.GeoPoint testing', () => { Parse.Object.saveAll(objects).then(() => { const query = new Parse.Query(TestObject); const point = new Parse.GeoPoint(1.0, -1.0); - query.withinRadians('location', point, 3.14); + query.withinRadians('location', point, 3.14, true); return query.find(); }).then((results) => { equal(results.length, 3); @@ -162,7 +162,7 @@ describe('Parse.GeoPoint testing', () => { Parse.Object.saveAll(objects, function() { const query = new Parse.Query(TestObject); const point = new Parse.GeoPoint(1.0, -1.0); - query.withinRadians('location', point, 3.14 * 0.5); + query.withinRadians('location', point, 3.14 * 0.5, true); query.find({ success: function(results) { equal(results.length, 2); @@ -186,7 +186,7 @@ describe('Parse.GeoPoint testing', () => { Parse.Object.saveAll(objects, function() { const query = new Parse.Query(TestObject); const point = new Parse.GeoPoint(1.0, -1.0); - query.withinRadians('location', point, 3.14 * 0.25); + query.withinRadians('location', point, 3.14 * 0.25, true); query.find({ success: function(results) { equal(results.length, 1); @@ -218,7 +218,7 @@ describe('Parse.GeoPoint testing', () => { const sfo = new Parse.GeoPoint(37.6189722, -122.3748889); const query = new Parse.Query(TestObject); // Honolulu is 4300 km away from SFO on a sphere ;) - query.withinKilometers('location', sfo, 4800.0); + query.withinKilometers('location', sfo, 4800.0, true); query.find({ success: function(results) { equal(results.length, 3); @@ -232,7 +232,7 @@ describe('Parse.GeoPoint testing', () => { makeSomeGeoPoints(function() { const sfo = new Parse.GeoPoint(37.6189722, -122.3748889); const query = new Parse.Query(TestObject); - query.withinKilometers('location', sfo, 3700.0); + query.withinKilometers('location', sfo, 3700.0, true); query.find({ success: function(results) { equal(results.length, 2); @@ -248,7 +248,7 @@ describe('Parse.GeoPoint testing', () => { makeSomeGeoPoints(function() { const sfo = new Parse.GeoPoint(37.6189722, -122.3748889); const query = new Parse.Query(TestObject); - query.withinKilometers('location', sfo, 100.0); + query.withinKilometers('location', sfo, 100.0, true); query.find({ success: function(results) { equal(results.length, 1); @@ -263,7 +263,7 @@ describe('Parse.GeoPoint testing', () => { makeSomeGeoPoints(function() { const sfo = new Parse.GeoPoint(37.6189722, -122.3748889); const query = new Parse.Query(TestObject); - query.withinKilometers('location', sfo, 10.0); + query.withinKilometers('location', sfo, 10.0, true); query.find({ success: function(results) { equal(results.length, 0); @@ -291,7 +291,7 @@ describe('Parse.GeoPoint testing', () => { makeSomeGeoPoints(function() { const sfo = new Parse.GeoPoint(37.6189722, -122.3748889); const query = new Parse.Query(TestObject); - query.withinMiles('location', sfo, 2200.0); + query.withinMiles('location', sfo, 2200.0, true); query.find({ success: function(results) { equal(results.length, 2); @@ -323,7 +323,7 @@ describe('Parse.GeoPoint testing', () => { makeSomeGeoPoints(function() { const sfo = new Parse.GeoPoint(37.6189722, -122.3748889); const query = new Parse.Query(TestObject); - query.withinMiles('location', sfo, 10.0); + query.withinMiles('location', sfo, 10.0, true); query.find({ success: function(results) { equal(results.length, 0); @@ -367,6 +367,63 @@ describe('Parse.GeoPoint testing', () => { }); }); + it('works with withinGeo.nearSphere queries in kilometers', (done) => { + const inbound = new Parse.GeoPoint(1.5, 1.5); + const onbound = new Parse.GeoPoint(10, 10); + const outbound = new Parse.GeoPoint(20, 20); + const obj1 = new Parse.Object('TestObject', {location: inbound}); + const obj2 = new Parse.Object('TestObject', {location: onbound}); + const obj3 = new Parse.Object('TestObject', {location: outbound}); + Parse.Object.saveAll([obj1, obj2, obj3]).then(() => { + const center = new Parse.GeoPoint(0, 0); + const distanceInKilometers = 1569 + 1; // 1569km is the approximate distance between {0, 0} and {10, 10}. + const q = new Parse.Query(TestObject); + q.withinKilometers('location', center, distanceInKilometers, false); + return q.find(); + }).then(results => { + equal(results.length, 2); + done(); + }); + }); + + it('works with withinGeo.nearSphere queries in miles', (done) => { + const inbound = new Parse.GeoPoint(1.5, 1.5); + const onbound = new Parse.GeoPoint(10, 10); + const outbound = new Parse.GeoPoint(20, 20); + const obj1 = new Parse.Object('TestObject', {location: inbound}); + const obj2 = new Parse.Object('TestObject', {location: onbound}); + const obj3 = new Parse.Object('TestObject', {location: outbound}); + Parse.Object.saveAll([obj1, obj2, obj3]).then(() => { + const center = new Parse.GeoPoint(0, 0); + const distanceInMiles = 975 + 1; // 975miles is the approximate distance between {0, 0} and {10, 10}. + const q = new Parse.Query(TestObject); + q.withinMiles('location', center, distanceInMiles, false); + return q.find(); + }).then(results => { + equal(results.length, 2); + done(); + }); + }); + + it('works with withinGeo.nearSphere queries in radians', (done) => { + const inbound = new Parse.GeoPoint(1.5, 1.5); + const onbound = new Parse.GeoPoint(10, 10); + const outbound = new Parse.GeoPoint(20, 20); + const obj1 = new Parse.Object('TestObject', {location: inbound}); + const obj2 = new Parse.Object('TestObject', {location: onbound}); + const obj3 = new Parse.Object('TestObject', {location: outbound}); + Parse.Object.saveAll([obj1, obj2, obj3]).then(() => { + const center = new Parse.GeoPoint(0, 0); + const distanceInRadians = 0.246 + 0.001; // 0.246radians is the approximate distance between {0, 0} and {10, 10}. + const q = new Parse.Query(TestObject); + q.withinRadians('location', center, distanceInRadians, false); + return q.find(); + }).then(results => { + equal(results.length, 2); + done(); + }); + }); + it('supports a sub-object with a geo point', done => { const point = new Parse.GeoPoint(44.0, -11.0); const obj = new TestObject(); diff --git a/spec/QueryTools.spec.js b/spec/QueryTools.spec.js index 7069725214..3eb9ae4d7e 100644 --- a/spec/QueryTools.spec.js +++ b/spec/QueryTools.spec.js @@ -373,10 +373,38 @@ describe('matchesQuery', function() { q = new Parse.Query('Checkin'); pt.location = new Parse.GeoPoint(40, 40); - q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.3); + q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.3, true); expect(matchesQuery(pt, q)).toBe(true); - q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.2); + q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.2, true); + expect(matchesQuery(pt, q)).toBe(false); + }); + + it('matches geoWithin.centerSphere queries', function() { + let q = new Parse.Query('Checkin'); + q.near('location', new Parse.GeoPoint(20, 20)); + // With no max distance, any GeoPoint is 'near' + const pt = { + id: new Id('Checkin', 'C1'), + location: new Parse.GeoPoint(40, 40) + }; + const ptUndefined = { + id: new Id('Checkin', 'C1') + }; + const ptNull = { + id: new Id('Checkin', 'C1'), + location: null + }; + expect(matchesQuery(pt, q)).toBe(true); + expect(matchesQuery(ptUndefined, q)).toBe(false); + expect(matchesQuery(ptNull, q)).toBe(false); + + q = new Parse.Query('Checkin'); + pt.location = new Parse.GeoPoint(40, 40); + q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.3, false); + expect(matchesQuery(pt, q)).toBe(true); + + q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.2, false); expect(matchesQuery(pt, q)).toBe(false); });