Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for JS SDK nearsphere convenience methods #4827

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 67 additions & 10 deletions spec/ParseGeoPoint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
32 changes: 30 additions & 2 deletions spec/QueryTools.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down