it('matches $nearSphere queries', function() { let q = new Parse.Query('Checkin'); q.near('location', new Parse.GeoPoint(20, 20)); // With no max distance, any GeoPoint is 'near' const pt = { id: new Id('Checkin', 'C1'), location: new Parse.GeoPoint(40, 40), }; const ptUndefined = { id: new Id('Checkin', 'C1'), }; const ptNull = { id: new Id('Checkin', 'C1'), location: null, }; expect(matchesQuery(pt, q)).toBe(true); expect(matchesQuery(ptUndefined, q)).toBe(false); expect(matchesQuery(ptNull, q)).toBe(false); q = new Parse.Query('Checkin'); pt.location = new Parse.GeoPoint(40, 40); q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.3); expect(matchesQuery(pt, q)).toBe(true); q.withinRadians('location', new Parse.GeoPoint(30, 30), 0.2); expect(matchesQuery(pt, q)).toBe(false); });
const obj1 = new GeoObject({ value: 1, location: new Parse.GeoPoint(1, 1), date: new Date(1) }); const obj2 = new GeoObject({ value: 2, location: new Parse.GeoPoint(2, 1), date: new Date(2) }); const obj3 = new GeoObject({ value: 3, location: new Parse.GeoPoint(3, 1), date: new Date(3) }); await Parse.Object.saveAll([obj1, obj2, obj3]);
it('does not change inner objects if the key has the same name as a geopoint field on the class, and the value is an array of length 2, or if the key has the same name as a file field on the class, and the value is a string', done => { const file = new Parse.File('myfile.txt', { base64: 'eAo=' }); file .save() .then(f => { const obj = new Parse.Object('O'); obj.set('fileField', f); obj.set('geoField', new Parse.GeoPoint(0, 0)); obj.set('innerObj', { fileField: 'data', geoField: [1, 2], }); return obj.save(); }) .then(object => object.fetch()) .then(object => { expect(object.get('innerObj')).toEqual({ fileField: 'data', geoField: [1, 2], }); done(); }) .catch(e => { jfail(e); done(); }); });
it('withJSON supports geoWithin.centerSphere', (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 }); const center = new Parse.GeoPoint(0, 0); const distanceInKilometers = 1569 + 1; // 1569km is the approximate distance between {0, 0} and {10, 10}. Parse.Object.saveAll([obj1, obj2, obj3])
it('matches $within queries', function() { const caltrainStation = { id: new Id('Checkin', 'C1'), location: new Parse.GeoPoint(37.776346, -122.394218), name: 'Caltrain', }; location: new Parse.GeoPoint(37.325635, -121.945753), name: 'Santa Clara', }; new Parse.GeoPoint(37.708813, -122.526398), new Parse.GeoPoint(37.822802, -122.373962) ); new Parse.GeoPoint(37.822802, -122.373962), new Parse.GeoPoint(37.708813, -122.526398) ); new Parse.GeoPoint(37.708813, -122.373962), new Parse.GeoPoint(37.822802, -122.526398) );
const obj1 = new GeoObject({ value: 1, location: new Parse.GeoPoint(1, 1), date: new Date(1) }); const obj2 = new GeoObject({ value: 2, location: new Parse.GeoPoint(2, 1), date: new Date(2) }); const obj3 = new GeoObject({ value: 3, location: new Parse.GeoPoint(3, 1), date: new Date(3) }); await Parse.Object.saveAll([obj1, obj2, obj3]);
const obj1 = new GeoObject({ value: 1, location: new Parse.GeoPoint(1, 1), date: new Date(1) }); const obj2 = new GeoObject({ value: 2, location: new Parse.GeoPoint(2, 1), date: new Date(2) }); const obj3 = new GeoObject({ value: 3, location: new Parse.GeoPoint(3, 1), date: new Date(3) }); await Parse.Object.saveAll([obj1, obj2, obj3]);