Fixes issue affecting liveQuery on location null/undefined values (#4171)
This commit is contained in:
committed by
Natan Rolnik
parent
d0184f438d
commit
8d8a8b250e
@@ -360,7 +360,16 @@ describe('matchesQuery', function() {
|
|||||||
id: new Id('Checkin', 'C1'),
|
id: new Id('Checkin', 'C1'),
|
||||||
location: new Parse.GeoPoint(40, 40)
|
location: new Parse.GeoPoint(40, 40)
|
||||||
};
|
};
|
||||||
|
var ptUndefined = {
|
||||||
|
id: new Id('Checkin', 'C1')
|
||||||
|
};
|
||||||
|
var ptNull = {
|
||||||
|
id: new Id('Checkin', 'C1'),
|
||||||
|
location: null
|
||||||
|
};
|
||||||
expect(matchesQuery(pt, q)).toBe(true);
|
expect(matchesQuery(pt, q)).toBe(true);
|
||||||
|
expect(matchesQuery(ptUndefined, q)).toBe(false);
|
||||||
|
expect(matchesQuery(ptNull, q)).toBe(false);
|
||||||
|
|
||||||
q = new Parse.Query('Checkin');
|
q = new Parse.Query('Checkin');
|
||||||
pt.location = new Parse.GeoPoint(40, 40);
|
pt.location = new Parse.GeoPoint(40, 40);
|
||||||
@@ -384,6 +393,17 @@ describe('matchesQuery', function() {
|
|||||||
name: 'Santa Clara'
|
name: 'Santa Clara'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var noLocation = {
|
||||||
|
id: new Id('Checkin', 'C2'),
|
||||||
|
name: 'Santa Clara'
|
||||||
|
};
|
||||||
|
|
||||||
|
var nullLocation = {
|
||||||
|
id: new Id('Checkin', 'C2'),
|
||||||
|
location: null,
|
||||||
|
name: 'Santa Clara'
|
||||||
|
};
|
||||||
|
|
||||||
var q = new Parse.Query('Checkin').withinGeoBox(
|
var q = new Parse.Query('Checkin').withinGeoBox(
|
||||||
'location',
|
'location',
|
||||||
new Parse.GeoPoint(37.708813, -122.526398),
|
new Parse.GeoPoint(37.708813, -122.526398),
|
||||||
@@ -392,7 +412,8 @@ describe('matchesQuery', function() {
|
|||||||
|
|
||||||
expect(matchesQuery(caltrainStation, q)).toBe(true);
|
expect(matchesQuery(caltrainStation, q)).toBe(true);
|
||||||
expect(matchesQuery(santaClara, q)).toBe(false);
|
expect(matchesQuery(santaClara, q)).toBe(false);
|
||||||
|
expect(matchesQuery(noLocation, q)).toBe(false);
|
||||||
|
expect(matchesQuery(nullLocation, q)).toBe(false);
|
||||||
// Invalid rectangles
|
// Invalid rectangles
|
||||||
q = new Parse.Query('Checkin').withinGeoBox(
|
q = new Parse.Query('Checkin').withinGeoBox(
|
||||||
'location',
|
'location',
|
||||||
|
|||||||
@@ -262,10 +262,16 @@ function matchesKeyConstraints(object, key, constraints) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '$nearSphere':
|
case '$nearSphere':
|
||||||
|
if (!compareTo || !object[key]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var distance = compareTo.radiansTo(object[key]);
|
var distance = compareTo.radiansTo(object[key]);
|
||||||
var max = constraints.$maxDistance || Infinity;
|
var max = constraints.$maxDistance || Infinity;
|
||||||
return distance <= max;
|
return distance <= max;
|
||||||
case '$within':
|
case '$within':
|
||||||
|
if (!compareTo || !object[key]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var southWest = compareTo.$box[0];
|
var southWest = compareTo.$box[0];
|
||||||
var northEast = compareTo.$box[1];
|
var northEast = compareTo.$box[1];
|
||||||
if (southWest.latitude > northEast.latitude ||
|
if (southWest.latitude > northEast.latitude ||
|
||||||
|
|||||||
Reference in New Issue
Block a user