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

Added WithinPolygon to Query #438

Merged
merged 6 commits into from
Jun 20, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
reused objects for test
  • Loading branch information
dplewis committed Jun 20, 2017
commit 975d5572b4853af378b4c54aa169fb601ca700db
81 changes: 25 additions & 56 deletions integration/test/ParseGeoPointTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,86 +238,55 @@ describe('Geo Point', () => {
});

it('supports withinPolygon open path', (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 TestObject({location: inbound});
const obj2 = new TestObject({location: onbound});
const obj3 = new TestObject({location: outbound});
Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
const points = [
new Parse.GeoPoint(0, 0),
new Parse.GeoPoint(0, 10),
new Parse.GeoPoint(10, 10),
new Parse.GeoPoint(10, 0)
];
const query = new Parse.Query(TestObject);
query.withinPolygon('location', points);
return query.find();
}).then((results) => {
const points = [
new Parse.GeoPoint(38.52, -121.50),
new Parse.GeoPoint(37.75, -157.93),
new Parse.GeoPoint(37.578072, -121.379914)
];
const query = new Parse.Query(TestObject);
query.withinPolygon('location', points);
return query.find().then((results) => {
assert.equal(results.length, 2);
done();
});
});

it('supports withinPolygon closed path', (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 TestObject({location: inbound});
const obj2 = new TestObject({location: onbound});
const obj3 = new TestObject({location: outbound});
Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
const points = [
new Parse.GeoPoint(0, 0),
new Parse.GeoPoint(0, 10),
new Parse.GeoPoint(10, 10),
new Parse.GeoPoint(10, 0),
new Parse.GeoPoint(0, 0)
];
const query = new Parse.Query(TestObject);
query.withinPolygon('location', points);
return query.find();
}).then((results) => {
const points = [
new Parse.GeoPoint(38.52, -121.50),
new Parse.GeoPoint(37.75, -157.93),
new Parse.GeoPoint(37.578072, -121.379914)
];
const query = new Parse.Query(TestObject);
query.withinPolygon('location', points);
return query.find().then((results) => {
assert.equal(results.length, 2);
done();
});
});

it('non array withinPolygon', (done) => {
const point = new Parse.GeoPoint(1.5, 1.5);
const obj = new TestObject({location: point});
obj.save().then(() => {
const query = new Parse.Query(TestObject);
query.withinPolygon('location', 1234);
return query.find();
}).fail((err) => {
const query = new Parse.Query(TestObject);
query.withinPolygon('location', 1234);
return query.find().fail((err) => {
assert.equal(err.code, Parse.Error.INVALID_JSON);
done();
});
});

it('invalid array withinPolygon', (done) => {
const point = new Parse.GeoPoint(1.5, 1.5);
const obj = new TestObject({location: point});
obj.save().then(() => {
const query = new Parse.Query(TestObject);
query.withinPolygon('location', [obj]);
return query.find();
}).fail((err) => {
const query = new Parse.Query(TestObject);
query.withinPolygon('location', [1234]);
return query.find().fail((err) => {
assert.equal(err.code, Parse.Error.INVALID_JSON);
done();
});
});

it('minimum 3 points withinPolygon', (done) => {
const point = new Parse.GeoPoint(1.5, 1.5);
const obj = new TestObject({location: point});
obj.save().then(() => {
const query = new Parse.Query(TestObject);
query.withinPolygon('location', []);
return query.find();
}).fail((err) => {
const query = new Parse.Query(TestObject);
query.withinPolygon('location', []);
return query.find().fail((err) => {
assert.equal(err.code, Parse.Error.INVALID_JSON);
done();
});
Expand Down