From 0acd8c6c0fc2c93ab34ba82dd1394e9db6eeef7d Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Wed, 3 Feb 2016 19:50:03 -0800 Subject: [PATCH 1/3] Add transform rest to mongo tests for geo points. --- spec/transform.spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/transform.spec.js b/spec/transform.spec.js index c581c5d6c3..528c46bfa1 100644 --- a/spec/transform.spec.js +++ b/spec/transform.spec.js @@ -61,6 +61,29 @@ describe('transformCreate', () => { // This just checks that it doesn't crash, but it should check format. done(); }); + + describe('GeoPoints', () => { + it('plain', (done) => { + var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180}; + var out = transform.transformCreate(dummySchema, null, {location: geoPoint}); + expect(out.location).toEqual([180, -180]); + done(); + }); + + it('in array', (done) => { + var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180}; + var out = transform.transformCreate(dummySchema, null, {locations: [geoPoint, geoPoint]}); + expect(out.locations).toEqual([geoPoint, geoPoint]); + done(); + }); + + it('in sub-object', (done) => { + var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180}; + var out = transform.transformCreate(dummySchema, null, { locations: { start: geoPoint }}); + expect(out).toEqual({ locations: { start: geoPoint } }); + done(); + }); + }); }); describe('transformWhere', () => { From 3cd7f7dd73f4a449a4e704b27fc3fa4b0e9df62a Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Wed, 3 Feb 2016 19:50:22 -0800 Subject: [PATCH 2/3] Add geo point in subobject and array end-to-end tests. --- spec/ParseGeoPoint.spec.js | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/spec/ParseGeoPoint.spec.js b/spec/ParseGeoPoint.spec.js index f5b54bca55..7d6a829190 100644 --- a/spec/ParseGeoPoint.spec.js +++ b/spec/ParseGeoPoint.spec.js @@ -287,4 +287,47 @@ describe('Parse.GeoPoint testing', () => { done(); }); }); + + it('supports a sub-object with a geo point', done => { + var point = new Parse.GeoPoint(44.0, -11.0); + var obj = new TestObject(); + obj.set('subobject', { location: point }); + obj.save(null, { + success: function() { + var query = new Parse.Query(TestObject); + query.find({ + success: function(results) { + equal(results.length, 1); + var pointAgain = results[0].get('subobject')['location']; + ok(pointAgain); + equal(pointAgain.latitude, 44.0); + equal(pointAgain.longitude, -11.0); + done(); + } + }); + } + }); + }); + + it('supports array of geo points', done => { + var point1 = new Parse.GeoPoint(44.0, -11.0); + var point2 = new Parse.GeoPoint(22.0, -55.0); + var obj = new TestObject(); + obj.set('locations', [ point1, point2 ]); + obj.save(null, { + success: function() { + var query = new Parse.Query(TestObject); + query.find({ + success: function(results) { + equal(results.length, 1); + var locations = results[0].get('locations'); + expect(locations.length).toEqual(2); + expect(locations[0]).toEqual(point1); + expect(locations[1]).toEqual(point2); + done(); + } + }); + } + }); + }); }); From 437e7726ed72b801eda8ba886d04c4b9252044ea Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Wed, 3 Feb 2016 20:06:22 -0800 Subject: [PATCH 3/3] Fix storage of GeoPoints in nested arrays/maps. --- transform.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/transform.js b/transform.js index 26e296ef56..7bb24bc7de 100644 --- a/transform.js +++ b/transform.js @@ -367,7 +367,10 @@ function transformAtom(atom, force, options) { return new Date(atom.iso); } if (atom.__type == 'GeoPoint') { - return [atom.longitude, atom.latitude]; + if (!inArray && !inObject) { + return [atom.longitude, atom.latitude]; + } + return atom; } if (atom.__type == 'Bytes') { return new mongodb.Binary(new Buffer(atom.base64, 'base64'));