Skip to content
This repository was archived by the owner on Jan 26, 2021. It is now read-only.

Commit a392a52

Browse files
committed
Merge pull request #89 from brenmcnamara/master
Checks for multiple GeoPoints when mutating object (Issue 85)
2 parents 6422e49 + 3f4a311 commit a392a52

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Mutation.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ function validateColumn(column: string) {
6565
}
6666

6767
function validateFields(data) {
68+
// Check for multiple GeoPoints.
69+
var geoPointCount = 0;
70+
for (var prop in data) {
71+
if (data.hasOwnProperty(prop) &&
72+
(data[prop] instanceof Parse.GeoPoint)) {
73+
++geoPointCount;
74+
if (geoPointCount > 1) {
75+
throw Error('There can only be 1 GeoPoint when mutating an object.');
76+
}
77+
}
78+
}
79+
6880
if (data.hasOwnProperty('objectId')) {
6981
warning('Ignoring reserved field: objectId');
7082
delete data.objectId;

src/__tests__/Mutation-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ describe('Mutation Generators', function() {
4848
expect(result instanceof Parse.Promise).toBe(true);
4949
});
5050

51+
it("fails to generate a Set Mutation with multiple GeoPoints", function () {
52+
expect(function () {
53+
var id = new Id('Klass', '01');
54+
Mutation.Set(id, {
55+
g1: new Parse.GeoPoint(),
56+
g2: new Parse.GeoPoint(),
57+
});
58+
}).toThrow('There can only be 1 GeoPoint when mutating an object.');
59+
});
60+
5161
it('generates an Unset Mutation', function() {
5262
var id = new Id('Klass', 'O1');
5363
var m = Mutation.Unset(id, 'no_more');

0 commit comments

Comments
 (0)