Skip to content

Commit ee5e06c

Browse files
committed
Merge pull request #231 from ParsePlatform/nlutsenko.transform.geopoint
Fixed storage of GeoPoints in nested arrays/maps.
2 parents 808d2cc + 437e772 commit ee5e06c

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

spec/ParseGeoPoint.spec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,47 @@ describe('Parse.GeoPoint testing', () => {
287287
done();
288288
});
289289
});
290+
291+
it('supports a sub-object with a geo point', done => {
292+
var point = new Parse.GeoPoint(44.0, -11.0);
293+
var obj = new TestObject();
294+
obj.set('subobject', { location: point });
295+
obj.save(null, {
296+
success: function() {
297+
var query = new Parse.Query(TestObject);
298+
query.find({
299+
success: function(results) {
300+
equal(results.length, 1);
301+
var pointAgain = results[0].get('subobject')['location'];
302+
ok(pointAgain);
303+
equal(pointAgain.latitude, 44.0);
304+
equal(pointAgain.longitude, -11.0);
305+
done();
306+
}
307+
});
308+
}
309+
});
310+
});
311+
312+
it('supports array of geo points', done => {
313+
var point1 = new Parse.GeoPoint(44.0, -11.0);
314+
var point2 = new Parse.GeoPoint(22.0, -55.0);
315+
var obj = new TestObject();
316+
obj.set('locations', [ point1, point2 ]);
317+
obj.save(null, {
318+
success: function() {
319+
var query = new Parse.Query(TestObject);
320+
query.find({
321+
success: function(results) {
322+
equal(results.length, 1);
323+
var locations = results[0].get('locations');
324+
expect(locations.length).toEqual(2);
325+
expect(locations[0]).toEqual(point1);
326+
expect(locations[1]).toEqual(point2);
327+
done();
328+
}
329+
});
330+
}
331+
});
332+
});
290333
});

spec/transform.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ describe('transformCreate', () => {
6161
// This just checks that it doesn't crash, but it should check format.
6262
done();
6363
});
64+
65+
describe('GeoPoints', () => {
66+
it('plain', (done) => {
67+
var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180};
68+
var out = transform.transformCreate(dummySchema, null, {location: geoPoint});
69+
expect(out.location).toEqual([180, -180]);
70+
done();
71+
});
72+
73+
it('in array', (done) => {
74+
var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180};
75+
var out = transform.transformCreate(dummySchema, null, {locations: [geoPoint, geoPoint]});
76+
expect(out.locations).toEqual([geoPoint, geoPoint]);
77+
done();
78+
});
79+
80+
it('in sub-object', (done) => {
81+
var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180};
82+
var out = transform.transformCreate(dummySchema, null, { locations: { start: geoPoint }});
83+
expect(out).toEqual({ locations: { start: geoPoint } });
84+
done();
85+
});
86+
});
6487
});
6588

6689
describe('transformWhere', () => {

transform.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,10 @@ function transformAtom(atom, force, options) {
367367
return new Date(atom.iso);
368368
}
369369
if (atom.__type == 'GeoPoint') {
370-
return [atom.longitude, atom.latitude];
370+
if (!inArray && !inObject) {
371+
return [atom.longitude, atom.latitude];
372+
}
373+
return atom;
371374
}
372375
if (atom.__type == 'Bytes') {
373376
return new mongodb.Binary(new Buffer(atom.base64, 'base64'));

0 commit comments

Comments
 (0)