@@ -5,7 +5,6 @@ const rp = require('request-promise');
|
||||
const TestObject = Parse.Object.extend('TestObject');
|
||||
|
||||
describe('Parse.GeoPoint testing', () => {
|
||||
|
||||
it('geo point roundtrip', async () => {
|
||||
const point = new Parse.GeoPoint(44.0, -11.0);
|
||||
const obj = new TestObject();
|
||||
@@ -20,74 +19,87 @@ describe('Parse.GeoPoint testing', () => {
|
||||
equal(pointAgain.longitude, -11.0);
|
||||
});
|
||||
|
||||
it('update geopoint', (done) => {
|
||||
it('update geopoint', done => {
|
||||
const oldPoint = new Parse.GeoPoint(44.0, -11.0);
|
||||
const newPoint = new Parse.GeoPoint(24.0, 19.0);
|
||||
const obj = new TestObject();
|
||||
obj.set('location', oldPoint);
|
||||
obj.save().then(() => {
|
||||
obj.set('location', newPoint);
|
||||
return obj.save();
|
||||
}).then(() => {
|
||||
const query = new Parse.Query(TestObject);
|
||||
return query.get(obj.id);
|
||||
}).then((result) => {
|
||||
const point = result.get('location');
|
||||
equal(point.latitude, newPoint.latitude);
|
||||
equal(point.longitude, newPoint.longitude);
|
||||
done();
|
||||
});
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
obj.set('location', newPoint);
|
||||
return obj.save();
|
||||
})
|
||||
.then(() => {
|
||||
const query = new Parse.Query(TestObject);
|
||||
return query.get(obj.id);
|
||||
})
|
||||
.then(result => {
|
||||
const point = result.get('location');
|
||||
equal(point.latitude, newPoint.latitude);
|
||||
equal(point.longitude, newPoint.longitude);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('has the correct __type field in the json response', async (done) => {
|
||||
it('has the correct __type field in the json response', async done => {
|
||||
const point = new Parse.GeoPoint(44.0, -11.0);
|
||||
const obj = new TestObject();
|
||||
obj.set('location', point);
|
||||
obj.set('name', 'Zhoul')
|
||||
obj.set('name', 'Zhoul');
|
||||
await obj.save();
|
||||
Parse.Cloud.httpRequest({
|
||||
url: 'http://localhost:8378/1/classes/TestObject/' + obj.id,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test'
|
||||
}
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
}).then(response => {
|
||||
equal(response.data.location.__type, 'GeoPoint');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('creating geo point exception two fields', (done) => {
|
||||
it('creating geo point exception two fields', done => {
|
||||
const point = new Parse.GeoPoint(20, 20);
|
||||
const obj = new TestObject();
|
||||
obj.set('locationOne', point);
|
||||
obj.set('locationTwo', point);
|
||||
obj.save().then(() => {
|
||||
fail('expected error');
|
||||
}, (err) => {
|
||||
equal(err.code, Parse.Error.INCORRECT_TYPE);
|
||||
done();
|
||||
});
|
||||
obj.save().then(
|
||||
() => {
|
||||
fail('expected error');
|
||||
},
|
||||
err => {
|
||||
equal(err.code, Parse.Error.INCORRECT_TYPE);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// TODO: This should also have support in postgres, or higher level database agnostic support.
|
||||
it_exclude_dbs(['postgres'])('updating geo point exception two fields', async (done) => {
|
||||
const point = new Parse.GeoPoint(20, 20);
|
||||
const obj = new TestObject();
|
||||
obj.set('locationOne', point);
|
||||
await obj.save();
|
||||
obj.set('locationTwo', point);
|
||||
obj.save().then(() => {
|
||||
fail('expected error');
|
||||
}, (err) => {
|
||||
equal(err.code, Parse.Error.INCORRECT_TYPE);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it_exclude_dbs(['postgres'])(
|
||||
'updating geo point exception two fields',
|
||||
async done => {
|
||||
const point = new Parse.GeoPoint(20, 20);
|
||||
const obj = new TestObject();
|
||||
obj.set('locationOne', point);
|
||||
await obj.save();
|
||||
obj.set('locationTwo', point);
|
||||
obj.save().then(
|
||||
() => {
|
||||
fail('expected error');
|
||||
},
|
||||
err => {
|
||||
equal(err.code, Parse.Error.INCORRECT_TYPE);
|
||||
done();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
it('geo line', async (done) => {
|
||||
it('geo line', async done => {
|
||||
const line = [];
|
||||
for (let i = 0; i < 10; ++i) {
|
||||
for (let i = 0; i < 10; ++i) {
|
||||
const obj = new TestObject();
|
||||
const point = new Parse.GeoPoint(i * 4.0 - 12.0, i * 3.2 - 11.0);
|
||||
obj.set('location', point);
|
||||
@@ -100,14 +112,14 @@ describe('Parse.GeoPoint testing', () => {
|
||||
const point = new Parse.GeoPoint(24, 19);
|
||||
query.equalTo('construct', 'line');
|
||||
query.withinMiles('location', point, 10000);
|
||||
const results = await query.find()
|
||||
const results = await query.find();
|
||||
equal(results.length, 10);
|
||||
equal(results[0].get('seq'), 9);
|
||||
equal(results[3].get('seq'), 6);
|
||||
done();
|
||||
});
|
||||
|
||||
it('geo max distance large', (done) => {
|
||||
it('geo max distance large', done => {
|
||||
const objects = [];
|
||||
[0, 1, 2].map(function(i) {
|
||||
const obj = new TestObject();
|
||||
@@ -116,18 +128,23 @@ describe('Parse.GeoPoint testing', () => {
|
||||
obj.set('index', i);
|
||||
objects.push(obj);
|
||||
});
|
||||
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);
|
||||
return query.find();
|
||||
}).then((results) => {
|
||||
equal(results.length, 3);
|
||||
done();
|
||||
}, (err) => {
|
||||
fail("Couldn't query GeoPoint");
|
||||
jfail(err)
|
||||
});
|
||||
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);
|
||||
return query.find();
|
||||
})
|
||||
.then(
|
||||
results => {
|
||||
equal(results.length, 3);
|
||||
done();
|
||||
},
|
||||
err => {
|
||||
fail("Couldn't query GeoPoint");
|
||||
jfail(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('geo max distance medium', async () => {
|
||||
@@ -139,7 +156,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
obj.set('index', i);
|
||||
objects.push(obj);
|
||||
});
|
||||
await Parse.Object.saveAll(objects)
|
||||
await Parse.Object.saveAll(objects);
|
||||
const query = new Parse.Query(TestObject);
|
||||
const point = new Parse.GeoPoint(1.0, -1.0);
|
||||
query.withinRadians('location', point, 3.14 * 0.5);
|
||||
@@ -169,7 +186,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
|
||||
const makeSomeGeoPoints = function() {
|
||||
const sacramento = new TestObject();
|
||||
sacramento.set('location', new Parse.GeoPoint(38.52, -121.50));
|
||||
sacramento.set('location', new Parse.GeoPoint(38.52, -121.5));
|
||||
sacramento.set('name', 'Sacramento');
|
||||
|
||||
const honolulu = new TestObject();
|
||||
@@ -183,7 +200,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
return Parse.Object.saveAll([sacramento, sf, honolulu]);
|
||||
};
|
||||
|
||||
it('geo max distance in km everywhere', async (done) => {
|
||||
it('geo max distance in km everywhere', async done => {
|
||||
await makeSomeGeoPoints();
|
||||
const sfo = new Parse.GeoPoint(37.6189722, -122.3748889);
|
||||
const query = new Parse.Query(TestObject);
|
||||
@@ -273,23 +290,25 @@ describe('Parse.GeoPoint testing', () => {
|
||||
equal(results[1].get('name'), 'Sacramento');
|
||||
});
|
||||
|
||||
it('works with geobox queries', (done) => {
|
||||
it('works with geobox queries', 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 sw = new Parse.GeoPoint(0, 0);
|
||||
const ne = new Parse.GeoPoint(10, 10);
|
||||
const query = new Parse.Query(TestObject);
|
||||
query.withinGeoBox('location', sw, ne);
|
||||
return query.find();
|
||||
}).then((results) => {
|
||||
equal(results.length, 2);
|
||||
done();
|
||||
});
|
||||
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 sw = new Parse.GeoPoint(0, 0);
|
||||
const ne = new Parse.GeoPoint(10, 10);
|
||||
const query = new Parse.Query(TestObject);
|
||||
query.withinGeoBox('location', sw, ne);
|
||||
return query.find();
|
||||
})
|
||||
.then(results => {
|
||||
equal(results.length, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('supports a sub-object with a geo point', async () => {
|
||||
@@ -310,7 +329,7 @@ describe('Parse.GeoPoint testing', () => {
|
||||
const point1 = new Parse.GeoPoint(44.0, -11.0);
|
||||
const point2 = new Parse.GeoPoint(22.0, -55.0);
|
||||
const obj = new TestObject();
|
||||
obj.set('locations', [ point1, point2 ]);
|
||||
obj.set('locations', [point1, point2]);
|
||||
await obj.save();
|
||||
const query = new Parse.Query(TestObject);
|
||||
const results = await query.find();
|
||||
@@ -321,349 +340,371 @@ describe('Parse.GeoPoint testing', () => {
|
||||
expect(locations[1]).toEqual(point2);
|
||||
});
|
||||
|
||||
it('equalTo geopoint', (done) => {
|
||||
it('equalTo geopoint', done => {
|
||||
const point = new Parse.GeoPoint(44.0, -11.0);
|
||||
const obj = new TestObject();
|
||||
obj.set('location', point);
|
||||
obj.save().then(() => {
|
||||
const query = new Parse.Query(TestObject);
|
||||
query.equalTo('location', point);
|
||||
return query.find();
|
||||
}).then((results) => {
|
||||
equal(results.length, 1);
|
||||
const loc = results[0].get('location');
|
||||
equal(loc.latitude, point.latitude);
|
||||
equal(loc.longitude, point.longitude);
|
||||
done();
|
||||
});
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
const query = new Parse.Query(TestObject);
|
||||
query.equalTo('location', point);
|
||||
return query.find();
|
||||
})
|
||||
.then(results => {
|
||||
equal(results.length, 1);
|
||||
const loc = results[0].get('location');
|
||||
equal(loc.latitude, point.latitude);
|
||||
equal(loc.longitude, point.longitude);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('supports withinPolygon open path', (done) => {
|
||||
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 Parse.Object('Polygon', {location: inbound});
|
||||
const obj2 = new Parse.Object('Polygon', {location: onbound});
|
||||
const obj3 = new Parse.Object('Polygon', {location: outbound});
|
||||
Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 10 },
|
||||
{ __type: 'GeoPoint', latitude: 10, longitude: 10 },
|
||||
{ __type: 'GeoPoint', latitude: 10, longitude: 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
});
|
||||
}).then((resp) => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
const obj1 = new Parse.Object('Polygon', { location: inbound });
|
||||
const obj2 = new Parse.Object('Polygon', { location: onbound });
|
||||
const obj3 = new Parse.Object('Polygon', { location: outbound });
|
||||
Parse.Object.saveAll([obj1, obj2, obj3])
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 10 },
|
||||
{ __type: 'GeoPoint', latitude: 10, longitude: 10 },
|
||||
{ __type: 'GeoPoint', latitude: 10, longitude: 0 },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('supports withinPolygon closed path', (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 Parse.Object('Polygon', {location: inbound});
|
||||
const obj2 = new Parse.Object('Polygon', {location: onbound});
|
||||
const obj3 = new Parse.Object('Polygon', {location: outbound});
|
||||
Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 10 },
|
||||
{ __type: 'GeoPoint', latitude: 10, longitude: 10 },
|
||||
{ __type: 'GeoPoint', latitude: 10, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
});
|
||||
}).then((resp) => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
const obj1 = new Parse.Object('Polygon', { location: inbound });
|
||||
const obj2 = new Parse.Object('Polygon', { location: onbound });
|
||||
const obj3 = new Parse.Object('Polygon', { location: outbound });
|
||||
Parse.Object.saveAll([obj1, obj2, obj3])
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 10 },
|
||||
{ __type: 'GeoPoint', latitude: 10, longitude: 10 },
|
||||
{ __type: 'GeoPoint', latitude: 10, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('supports withinPolygon Polygon object', (done) => {
|
||||
it('supports withinPolygon Polygon object', 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('Polygon', {location: inbound});
|
||||
const obj2 = new Parse.Object('Polygon', {location: onbound});
|
||||
const obj3 = new Parse.Object('Polygon', {location: outbound});
|
||||
const obj1 = new Parse.Object('Polygon', { location: inbound });
|
||||
const obj2 = new Parse.Object('Polygon', { location: onbound });
|
||||
const obj3 = new Parse.Object('Polygon', { location: outbound });
|
||||
const polygon = {
|
||||
__type: 'Polygon',
|
||||
coordinates: [
|
||||
[0, 0],
|
||||
[10, 0],
|
||||
[10, 10],
|
||||
[0, 10],
|
||||
[0, 0]
|
||||
]
|
||||
}
|
||||
Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: polygon
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
});
|
||||
}).then((resp) => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
coordinates: [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||
};
|
||||
Parse.Object.saveAll([obj1, obj2, obj3])
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: polygon,
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.results.length).toBe(2);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('invalid Polygon object withinPolygon', (done) => {
|
||||
it('invalid Polygon object withinPolygon', done => {
|
||||
const point = new Parse.GeoPoint(1.5, 1.5);
|
||||
const obj = new Parse.Object('Polygon', {location: point});
|
||||
const obj = new Parse.Object('Polygon', { location: point });
|
||||
const polygon = {
|
||||
__type: 'Polygon',
|
||||
coordinates: [
|
||||
[0, 0],
|
||||
[10, 0],
|
||||
]
|
||||
}
|
||||
obj.save().then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: polygon
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
coordinates: [[0, 0], [10, 0]],
|
||||
};
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: polygon,
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
}).then((resp) => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
}).catch((err) => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('out of bounds Polygon object withinPolygon', (done) => {
|
||||
it('out of bounds Polygon object withinPolygon', done => {
|
||||
const point = new Parse.GeoPoint(1.5, 1.5);
|
||||
const obj = new Parse.Object('Polygon', {location: point});
|
||||
const obj = new Parse.Object('Polygon', { location: point });
|
||||
const polygon = {
|
||||
__type: 'Polygon',
|
||||
coordinates: [
|
||||
[0, 0],
|
||||
[181, 0],
|
||||
[0, 10]
|
||||
]
|
||||
}
|
||||
obj.save().then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: polygon
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
coordinates: [[0, 0], [181, 0], [0, 10]],
|
||||
};
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: polygon,
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(1);
|
||||
done();
|
||||
});
|
||||
}).then((resp) => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
}).catch((err) => {
|
||||
expect(err.error.code).toEqual(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid input withinPolygon', (done) => {
|
||||
it('invalid input withinPolygon', done => {
|
||||
const point = new Parse.GeoPoint(1.5, 1.5);
|
||||
const obj = new Parse.Object('Polygon', {location: point});
|
||||
obj.save().then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: 1234
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
const obj = new Parse.Object('Polygon', { location: point });
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: 1234,
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
}).then((resp) => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
}).catch((err) => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid geoPoint withinPolygon', (done) => {
|
||||
it('invalid geoPoint withinPolygon', done => {
|
||||
const point = new Parse.GeoPoint(1.5, 1.5);
|
||||
const obj = new Parse.Object('Polygon', {location: point});
|
||||
obj.save().then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [
|
||||
{}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
const obj = new Parse.Object('Polygon', { location: point });
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [{}],
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
}).then((resp) => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
}).catch((err) => {
|
||||
expect(err.error.code).toEqual(Parse.Error.INVALID_JSON);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid latitude withinPolygon', (done) => {
|
||||
it('invalid latitude withinPolygon', done => {
|
||||
const point = new Parse.GeoPoint(1.5, 1.5);
|
||||
const obj = new Parse.Object('Polygon', {location: point});
|
||||
obj.save().then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 181, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
const obj = new Parse.Object('Polygon', { location: point });
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 181, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(1);
|
||||
done();
|
||||
});
|
||||
}).then((resp) => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
}).catch((err) => {
|
||||
expect(err.error.code).toEqual(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid longitude withinPolygon', (done) => {
|
||||
it('invalid longitude withinPolygon', done => {
|
||||
const point = new Parse.GeoPoint(1.5, 1.5);
|
||||
const obj = new Parse.Object('Polygon', {location: point});
|
||||
obj.save().then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 181 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
const obj = new Parse.Object('Polygon', { location: point });
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 181 },
|
||||
{ __type: 'GeoPoint', latitude: 0, longitude: 0 },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(1);
|
||||
done();
|
||||
});
|
||||
}).then((resp) => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
}).catch((err) => {
|
||||
expect(err.error.code).toEqual(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('minimum 3 points withinPolygon', (done) => {
|
||||
it('minimum 3 points withinPolygon', done => {
|
||||
const point = new Parse.GeoPoint(1.5, 1.5);
|
||||
const obj = new Parse.Object('Polygon', {location: point});
|
||||
obj.save().then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: []
|
||||
}
|
||||
}
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, '_method': 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey
|
||||
}
|
||||
const obj = new Parse.Object('Polygon', { location: point });
|
||||
obj
|
||||
.save()
|
||||
.then(() => {
|
||||
const where = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$polygon: [],
|
||||
},
|
||||
},
|
||||
};
|
||||
return rp.post({
|
||||
url: Parse.serverURL + '/classes/Polygon',
|
||||
json: { where, _method: 'GET' },
|
||||
headers: {
|
||||
'X-Parse-Application-Id': Parse.applicationId,
|
||||
'X-Parse-Javascript-Key': Parse.javaScriptKey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.then(resp => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
})
|
||||
.catch(err => {
|
||||
expect(err.error.code).toEqual(107);
|
||||
done();
|
||||
});
|
||||
}).then((resp) => {
|
||||
fail(`no request should succeed: ${JSON.stringify(resp)}`);
|
||||
done();
|
||||
}).catch((err) => {
|
||||
expect(err.error.code).toEqual(107);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user