From 2b7223355e113a8e4d5204a2273affb1cb9fc390 Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 28 Apr 2020 20:45:01 +0200 Subject: [PATCH] fix explain on user class (#6650) * added test case and fixed bug * enabled test case only for mongodb --- spec/ParseQuery.spec.js | 1294 +++++++++++++++++++-------------------- src/RestQuery.js | 2 +- 2 files changed, 645 insertions(+), 651 deletions(-) diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index ee4727404a..7dec9893f6 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -19,13 +19,13 @@ const masterKeyOptions = { }; describe('Parse.Query testing', () => { - it('basic query', function(done) { + it('basic query', function (done) { const baz = new TestObject({ foo: 'baz' }); const qux = new TestObject({ foo: 'qux' }); - Parse.Object.saveAll([baz, qux]).then(function() { + Parse.Object.saveAll([baz, qux]).then(function () { const query = new Parse.Query(TestObject); query.equalTo('foo', 'baz'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); equal(results[0].get('foo'), 'baz'); done(); @@ -33,18 +33,18 @@ describe('Parse.Query testing', () => { }); }); - it('searching for null', function(done) { + it('searching for null', function (done) { const baz = new TestObject({ foo: null }); const qux = new TestObject({ foo: 'qux' }); const qux2 = new TestObject({}); - Parse.Object.saveAll([baz, qux, qux2]).then(function() { + Parse.Object.saveAll([baz, qux, qux2]).then(function () { const query = new Parse.Query(TestObject); query.equalTo('foo', null); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 2); qux.set('foo', null); - qux.save().then(function() { - query.find().then(function(results) { + qux.save().then(function () { + query.find().then(function (results) { equal(results.length, 3); done(); }); @@ -53,18 +53,18 @@ describe('Parse.Query testing', () => { }); }); - it('searching for not null', function(done) { + it('searching for not null', function (done) { const baz = new TestObject({ foo: null }); const qux = new TestObject({ foo: 'qux' }); const qux2 = new TestObject({}); - Parse.Object.saveAll([baz, qux, qux2]).then(function() { + Parse.Object.saveAll([baz, qux, qux2]).then(function () { const query = new Parse.Query(TestObject); query.notEqualTo('foo', null); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); qux.set('foo', null); - qux.save().then(function() { - query.find().then(function(results) { + qux.save().then(function () { + query.find().then(function (results) { equal(results.length, 0); done(); }); @@ -73,7 +73,7 @@ describe('Parse.Query testing', () => { }); }); - it('notEqualTo with Relation is working', function(done) { + it('notEqualTo with Relation is working', function (done) { const user = new Parse.User(); user.setPassword('asdf'); user.setUsername('zxcv'); @@ -93,13 +93,13 @@ describe('Parse.Query testing', () => { user .signUp() - .then(function() { + .then(function () { return user1.signUp(); }) - .then(function() { + .then(function () { return user2.signUp(); }) - .then(function() { + .then(function () { const relLike1 = cake1.relation('liker'); relLike1.add([user, user1]); @@ -108,7 +108,7 @@ describe('Parse.Query testing', () => { return cake1.save(); }) - .then(function() { + .then(function () { const rellike2 = cake2.relation('liker'); rellike2.add([user, user1]); @@ -120,7 +120,7 @@ describe('Parse.Query testing', () => { return cake2.save(); }) - .then(function() { + .then(function () { const rellike3 = cake3.relation('liker'); rellike3.add(user); @@ -128,111 +128,111 @@ describe('Parse.Query testing', () => { relDislike3.add([user1, user2]); return cake3.save(); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); // User2 likes nothing so we should receive 0 query.equalTo('liker', user2); - return query.find().then(function(results) { + return query.find().then(function (results) { equal(results.length, 0); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); // User1 likes two of three cakes query.equalTo('liker', user1); - return query.find().then(function(results) { + return query.find().then(function (results) { // It should return 2 -> cake 1 and cake 2 equal(results.length, 2); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); // We want to know which cake the user1 is not appreciating -> cake3 query.notEqualTo('liker', user1); - return query.find().then(function(results) { + return query.find().then(function (results) { // Should return 1 -> the cake 3 equal(results.length, 1); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); // User2 is a hater of everything so we should receive 0 query.notEqualTo('hater', user2); - return query.find().then(function(results) { + return query.find().then(function (results) { equal(results.length, 0); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); // Only cake3 is liked by user query.notContainedIn('liker', [user1]); - return query.find().then(function(results) { + return query.find().then(function (results) { equal(results.length, 1); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); // All the users query.containedIn('liker', [user, user1, user2]); // Exclude user 1 query.notEqualTo('liker', user1); // Only cake3 is liked only by user1 - return query.find().then(function(results) { + return query.find().then(function (results) { equal(results.length, 1); const cake = results[0]; expect(cake.id).toBe(cake3.id); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); // Exclude user1 query.notEqualTo('liker', user1); // Only cake1 query.equalTo('objectId', cake1.id); // user1 likes cake1 so this should return no results - return query.find().then(function(results) { + return query.find().then(function (results) { equal(results.length, 0); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); query.notEqualTo('hater', user2); query.notEqualTo('liker', user2); // user2 doesn't like any cake so this should be 0 - return query.find().then(function(results) { + return query.find().then(function (results) { equal(results.length, 0); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); query.equalTo('hater', user); query.equalTo('liker', user); // user doesn't hate any cake so this should be 0 - return query.find().then(function(results) { + return query.find().then(function (results) { equal(results.length, 0); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); query.equalTo('hater', null); query.equalTo('liker', null); // user doesn't hate any cake so this should be 0 - return query.find().then(function(results) { + return query.find().then(function (results) { equal(results.length, 0); }); }) - .then(function() { + .then(function () { const query = new Parse.Query(Cake); query.equalTo('something', null); // user doesn't hate any cake so this should be 0 - return query.find().then(function(results) { + return query.find().then(function (results) { equal(results.length, 0); }); }) - .then(function() { + .then(function () { done(); }) - .catch(err => { + .catch((err) => { jfail(err); done(); }); @@ -262,48 +262,48 @@ describe('Parse.Query testing', () => { equal(results.length, 0); }); - it('query with limit', function(done) { + it('query with limit', function (done) { const baz = new TestObject({ foo: 'baz' }); const qux = new TestObject({ foo: 'qux' }); - Parse.Object.saveAll([baz, qux]).then(function() { + Parse.Object.saveAll([baz, qux]).then(function () { const query = new Parse.Query(TestObject); query.limit(1); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); }); }); - it('query with limit equal to maxlimit', function(done) { + it('query with limit equal to maxlimit', function (done) { const baz = new TestObject({ foo: 'baz' }); const qux = new TestObject({ foo: 'qux' }); reconfigureServer({ maxLimit: 1 }); - Parse.Object.saveAll([baz, qux]).then(function() { + Parse.Object.saveAll([baz, qux]).then(function () { const query = new Parse.Query(TestObject); query.limit(1); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); }); }); - it('query with limit exceeding maxlimit', function(done) { + it('query with limit exceeding maxlimit', function (done) { const baz = new TestObject({ foo: 'baz' }); const qux = new TestObject({ foo: 'qux' }); reconfigureServer({ maxLimit: 1 }); - Parse.Object.saveAll([baz, qux]).then(function() { + Parse.Object.saveAll([baz, qux]).then(function () { const query = new Parse.Query(TestObject); query.limit(2); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); }); }); - it('containedIn object array queries', function(done) { + it('containedIn object array queries', function (done) { const messageList = []; for (let i = 0; i < 4; ++i) { const message = new TestObject({}); @@ -314,7 +314,7 @@ describe('Parse.Query testing', () => { } Parse.Object.saveAll(messageList).then( - function() { + function () { equal(messageList.length, 4); const inList = []; @@ -324,24 +324,24 @@ describe('Parse.Query testing', () => { const query = new Parse.Query(TestObject); query.containedIn('prior', inList); query.find().then( - function(results) { + function (results) { equal(results.length, 2); done(); }, - function(e) { + function (e) { jfail(e); done(); } ); }, - e => { + (e) => { jfail(e); done(); } ); }); - it('containedIn null array', done => { + it('containedIn null array', (done) => { const emails = ['contact@xyz.com', 'contact@zyx.com', null]; const user = new Parse.User(); user.setUsername(emails[0]); @@ -353,7 +353,7 @@ describe('Parse.Query testing', () => { query.containedIn('username', emails); return query.find({ useMasterKey: true }); }) - .then(results => { + .then((results) => { equal(results.length, 1); done(); }, done.fail); @@ -377,7 +377,7 @@ describe('Parse.Query testing', () => { equal(result.get('nested').foo[0], "single'quote"); }); - it('nested containedIn string', done => { + it('nested containedIn string', (done) => { const sender1 = { group: ['A', 'B'] }; const sender2 = { group: ['A', 'C'] }; const sender3 = { group: ['B', 'C'] }; @@ -390,13 +390,13 @@ describe('Parse.Query testing', () => { query.containedIn('sender.group', ['A']); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 2); done(); }, done.fail); }); - it('nested containedIn number', done => { + it('nested containedIn number', (done) => { const sender1 = { group: [1, 2] }; const sender2 = { group: [1, 3] }; const sender3 = { group: [2, 3] }; @@ -409,13 +409,13 @@ describe('Parse.Query testing', () => { query.containedIn('sender.group', [1]); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 2); done(); }, done.fail); }); - it('containsAll number array queries', function(done) { + it('containsAll number array queries', function (done) { const NumberSet = Parse.Object.extend({ className: 'NumberSet' }); const objectsList = []; @@ -423,27 +423,27 @@ describe('Parse.Query testing', () => { objectsList.push(new NumberSet({ numbers: [1, 3, 4, 5] })); Parse.Object.saveAll(objectsList) - .then(function() { + .then(function () { const query = new Parse.Query(NumberSet); query.containsAll('numbers', [1, 2, 3]); query.find().then( - function(results) { + function (results) { equal(results.length, 1); done(); }, - function(err) { + function (err) { jfail(err); done(); } ); }) - .catch(err => { + .catch((err) => { jfail(err); done(); }); }); - it('containsAll string array queries', function(done) { + it('containsAll string array queries', function (done) { const StringSet = Parse.Object.extend({ className: 'StringSet' }); const objectsList = []; @@ -451,21 +451,21 @@ describe('Parse.Query testing', () => { objectsList.push(new StringSet({ strings: ['a', 'c', 'd', 'e'] })); Parse.Object.saveAll(objectsList) - .then(function() { + .then(function () { const query = new Parse.Query(StringSet); query.containsAll('strings', ['a', 'b', 'c']); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); }) - .catch(err => { + .catch((err) => { jfail(err); done(); }); }); - it('containsAll date array queries', function(done) { + it('containsAll date array queries', function (done) { const DateSet = Parse.Object.extend({ className: 'DateSet' }); function parseDate(iso8601) { @@ -492,8 +492,8 @@ describe('Parse.Query testing', () => { return new Date(Date.UTC(year, month, day, hour, minute, second, milli)); } - const makeDates = function(stringArray) { - return stringArray.map(function(dateStr) { + const makeDates = function (stringArray) { + return stringArray.map(function (dateStr) { return parseDate(dateStr + 'T00:00:00Z'); }); }; @@ -515,18 +515,18 @@ describe('Parse.Query testing', () => { }) ); - Parse.Object.saveAll(objectsList).then(function() { + Parse.Object.saveAll(objectsList).then(function () { const query = new Parse.Query(DateSet); query.containsAll( 'dates', makeDates(['2013-02-01', '2013-02-02', '2013-02-03']) ); query.find().then( - function(results) { + function (results) { equal(results.length, 1); done(); }, - function(e) { + function (e) { jfail(e); done(); } @@ -534,7 +534,7 @@ describe('Parse.Query testing', () => { }); }); - it('containsAll object array queries', function(done) { + it('containsAll object array queries', function (done) { const MessageSet = Parse.Object.extend({ className: 'MessageSet' }); const messageList = []; @@ -542,7 +542,7 @@ describe('Parse.Query testing', () => { messageList.push(new TestObject({ i: i })); } - Parse.Object.saveAll(messageList).then(function() { + Parse.Object.saveAll(messageList).then(function () { equal(messageList.length, 4); const messageSetList = []; @@ -554,14 +554,14 @@ describe('Parse.Query testing', () => { someList.push(messageList[3]); messageSetList.push(new MessageSet({ messages: someList })); - Parse.Object.saveAll(messageSetList).then(function() { + Parse.Object.saveAll(messageSetList).then(function () { const inList = []; inList.push(messageList[0]); inList.push(messageList[2]); const query = new Parse.Query(MessageSet); query.containsAll('messages', inList); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); @@ -569,7 +569,7 @@ describe('Parse.Query testing', () => { }); }); - it('containsAllStartingWith should match all strings that starts with string', done => { + it('containsAllStartingWith should match all strings that starts with string', (done) => { const object = new Parse.Object('Object'); object.set('strings', ['the', 'brown', 'lazy', 'fox', 'jumps']); const object2 = new Parse.Object('Object'); @@ -579,7 +579,7 @@ describe('Parse.Query testing', () => { const objectList = [object, object2, object3]; - Parse.Object.saveAll(objectList).then(results => { + Parse.Object.saveAll(objectList).then((results) => { equal(objectList.length, results.length); return request({ @@ -601,7 +601,7 @@ describe('Parse.Query testing', () => { 'Content-Type': 'application/json', }, }) - .then(function(response) { + .then(function (response) { const results = response.data; equal(results.results.length, 1); arrayContains(results.results, object); @@ -622,7 +622,7 @@ describe('Parse.Query testing', () => { }, }); }) - .then(function(response) { + .then(function (response) { const results = response.data; equal(results.results.length, 2); arrayContains(results.results, object); @@ -644,7 +644,7 @@ describe('Parse.Query testing', () => { }, }); }) - .then(function(response) { + .then(function (response) { const results = response.data; equal(results.results.length, 0); @@ -653,7 +653,7 @@ describe('Parse.Query testing', () => { }); }); - it('containsAllStartingWith values must be all of type starting with regex', done => { + it('containsAllStartingWith values must be all of type starting with regex', (done) => { const object = new Parse.Object('Object'); object.set('strings', ['the', 'brown', 'lazy', 'fox', 'jumps']); @@ -683,12 +683,12 @@ describe('Parse.Query testing', () => { }, }); }) - .then(done.fail, function() { + .then(done.fail, function () { done(); }); }); - it('containsAllStartingWith empty array values should return empty results', done => { + it('containsAllStartingWith empty array values should return empty results', (done) => { const object = new Parse.Object('Object'); object.set('strings', ['the', 'brown', 'lazy', 'fox', 'jumps']); @@ -714,16 +714,16 @@ describe('Parse.Query testing', () => { }); }) .then( - function(response) { + function (response) { const results = response.data; equal(results.results.length, 0); done(); }, - function() {} + function () {} ); }); - it('containsAllStartingWith single empty value returns empty results', done => { + it('containsAllStartingWith single empty value returns empty results', (done) => { const object = new Parse.Object('Object'); object.set('strings', ['the', 'brown', 'lazy', 'fox', 'jumps']); @@ -749,16 +749,16 @@ describe('Parse.Query testing', () => { }); }) .then( - function(response) { + function (response) { const results = response.data; equal(results.results.length, 0); done(); }, - function() {} + function () {} ); }); - it('containsAllStartingWith single regex value should return corresponding matching results', done => { + it('containsAllStartingWith single regex value should return corresponding matching results', (done) => { const object = new Parse.Object('Object'); object.set('strings', ['the', 'brown', 'lazy', 'fox', 'jumps']); const object2 = new Parse.Object('Object'); @@ -769,7 +769,7 @@ describe('Parse.Query testing', () => { const objectList = [object, object2, object3]; Parse.Object.saveAll(objectList) - .then(results => { + .then((results) => { equal(objectList.length, results.length); return request({ @@ -789,16 +789,16 @@ describe('Parse.Query testing', () => { }); }) .then( - function(response) { + function (response) { const results = response.data; equal(results.results.length, 2); done(); }, - function() {} + function () {} ); }); - it('containsAllStartingWith single invalid regex returns empty results', done => { + it('containsAllStartingWith single invalid regex returns empty results', (done) => { const object = new Parse.Object('Object'); object.set('strings', ['the', 'brown', 'lazy', 'fox', 'jumps']); @@ -823,17 +823,17 @@ describe('Parse.Query testing', () => { }); }) .then( - function(response) { + function (response) { const results = response.data; equal(results.results.length, 0); done(); }, - function() {} + function () {} ); }); - it('containedBy pointer array', done => { - const objects = Array.from(Array(10).keys()).map(idx => { + it('containedBy pointer array', (done) => { + const objects = Array.from(Array(10).keys()).map((idx) => { const obj = new Parse.Object('Object'); obj.set('key', idx); return obj; @@ -859,7 +859,7 @@ describe('Parse.Query testing', () => { }) .then(() => { // [1, 2, 3, 4, 5, 6, 7, 8, 9] - const pointers = objects.map(object => object.toPointer()); + const pointers = objects.map((object) => object.toPointer()); // Return all Parent where all parent.objects are contained in objects return request({ @@ -878,7 +878,7 @@ describe('Parse.Query testing', () => { }, }); }) - .then(response => { + .then((response) => { const results = response.data; expect(results.results[0].objectId).not.toBeUndefined(); expect(results.results[0].objectId).toBe(parent3.id); @@ -887,7 +887,7 @@ describe('Parse.Query testing', () => { }); }); - it('containedBy number array', done => { + it('containedBy number array', (done) => { const options = Object.assign({}, masterKeyOptions, { qs: { where: JSON.stringify({ @@ -907,7 +907,7 @@ describe('Parse.Query testing', () => { ) ); }) - .then(response => { + .then((response) => { const results = response.data; expect(results.results[0].objectId).not.toBeUndefined(); expect(results.results[0].objectId).toBe(obj3.id); @@ -916,7 +916,7 @@ describe('Parse.Query testing', () => { }); }); - it('containedBy empty array', done => { + it('containedBy empty array', (done) => { const options = Object.assign({}, masterKeyOptions, { qs: { where: JSON.stringify({ numbers: { $containedBy: [] } }), @@ -934,14 +934,14 @@ describe('Parse.Query testing', () => { ) ); }) - .then(response => { + .then((response) => { const results = response.data; expect(results.results.length).toBe(0); done(); }); }); - it('containedBy invalid query', done => { + it('containedBy invalid query', (done) => { const options = Object.assign({}, masterKeyOptions, { qs: { where: JSON.stringify({ objects: { $containedBy: 1234 } }), @@ -959,7 +959,7 @@ describe('Parse.Query testing', () => { ); }) .then(done.fail) - .catch(response => { + .catch((response) => { equal(response.data.code, Parse.Error.INVALID_JSON); equal(response.data.error, 'bad $containedBy: should be an array'); done(); @@ -970,72 +970,72 @@ describe('Parse.Query testing', () => { className: 'BoxedNumber', }); - it('equalTo queries', function(done) { - const makeBoxedNumber = function(i) { + it('equalTo queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.equalTo('number', 3); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); }); }); - it('equalTo undefined', function(done) { - const makeBoxedNumber = function(i) { + it('equalTo undefined', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.equalTo('number', undefined); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 0); done(); }); }); }); - it('lessThan queries', function(done) { - const makeBoxedNumber = function(i) { + it('lessThan queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.lessThan('number', 7); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 7); done(); }); }); }); - it('lessThanOrEqualTo queries', function(done) { - const makeBoxedNumber = function(i) { + it('lessThanOrEqualTo queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.lessThanOrEqualTo('number', 7); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 8); done(); }); }); }); - it('lessThan zero queries', done => { - const makeBoxedNumber = i => { + it('lessThan zero queries', (done) => { + const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; @@ -1046,14 +1046,14 @@ describe('Parse.Query testing', () => { query.lessThan('number', 0); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 3); done(); }); }); - it('lessThanOrEqualTo zero queries', done => { - const makeBoxedNumber = i => { + it('lessThanOrEqualTo zero queries', (done) => { + const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; @@ -1064,46 +1064,46 @@ describe('Parse.Query testing', () => { query.lessThanOrEqualTo('number', 0); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 4); done(); }); }); - it('greaterThan queries', function(done) { - const makeBoxedNumber = function(i) { + it('greaterThan queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.greaterThan('number', 7); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 2); done(); }); }); }); - it('greaterThanOrEqualTo queries', function(done) { - const makeBoxedNumber = function(i) { + it('greaterThanOrEqualTo queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.greaterThanOrEqualTo('number', 7); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 3); done(); }); }); }); - it('greaterThan zero queries', done => { - const makeBoxedNumber = i => { + it('greaterThan zero queries', (done) => { + const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; @@ -1114,14 +1114,14 @@ describe('Parse.Query testing', () => { query.greaterThan('number', 0); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 1); done(); }); }); - it('greaterThanOrEqualTo zero queries', done => { - const makeBoxedNumber = i => { + it('greaterThanOrEqualTo zero queries', (done) => { + const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; @@ -1132,64 +1132,64 @@ describe('Parse.Query testing', () => { query.greaterThanOrEqualTo('number', 0); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 2); done(); }); }); - it('lessThanOrEqualTo greaterThanOrEqualTo queries', function(done) { - const makeBoxedNumber = function(i) { + it('lessThanOrEqualTo greaterThanOrEqualTo queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.lessThanOrEqualTo('number', 7); query.greaterThanOrEqualTo('number', 7); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); }); }); - it('lessThan greaterThan queries', function(done) { - const makeBoxedNumber = function(i) { + it('lessThan greaterThan queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.lessThan('number', 9); query.greaterThan('number', 3); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 5); done(); }); }); }); - it('notEqualTo queries', function(done) { - const makeBoxedNumber = function(i) { + it('notEqualTo queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.notEqualTo('number', 5); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 9); done(); }); }); }); - it('notEqualTo zero queries', done => { - const makeBoxedNumber = i => { + it('notEqualTo zero queries', (done) => { + const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; @@ -1200,14 +1200,14 @@ describe('Parse.Query testing', () => { query.notEqualTo('number', 0); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 4); done(); }); }); - it('equalTo zero queries', done => { - const makeBoxedNumber = i => { + it('equalTo zero queries', (done) => { + const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; @@ -1218,14 +1218,14 @@ describe('Parse.Query testing', () => { query.equalTo('number', 0); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 1); done(); }); }); - it('number equalTo boolean queries', done => { - const makeBoxedNumber = i => { + it('number equalTo boolean queries', (done) => { + const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; @@ -1236,13 +1236,13 @@ describe('Parse.Query testing', () => { query.equalTo('number', false); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 0); done(); }); }); - it('equalTo false queries', done => { + it('equalTo false queries', (done) => { const obj1 = new TestObject({ field: false }); const obj2 = new TestObject({ field: true }); Parse.Object.saveAll([obj1, obj2]) @@ -1251,13 +1251,13 @@ describe('Parse.Query testing', () => { query.equalTo('field', false); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 1); done(); }); }); - it('where $eq false queries (rest)', done => { + it('where $eq false queries (rest)', (done) => { const options = Object.assign({}, masterKeyOptions, { qs: { where: JSON.stringify({ field: { $eq: false } }), @@ -1268,14 +1268,14 @@ describe('Parse.Query testing', () => { Parse.Object.saveAll([obj1, obj2]).then(() => { request( Object.assign({ url: Parse.serverURL + '/classes/TestObject' }, options) - ).then(resp => { + ).then((resp) => { equal(resp.data.results.length, 1); done(); }); }); }); - it('where $eq null queries (rest)', done => { + it('where $eq null queries (rest)', (done) => { const options = Object.assign({}, masterKeyOptions, { qs: { where: JSON.stringify({ field: { $eq: null } }), @@ -1286,31 +1286,31 @@ describe('Parse.Query testing', () => { Parse.Object.saveAll([obj1, obj2]).then(() => { return request( Object.assign({ url: Parse.serverURL + '/classes/TestObject' }, options) - ).then(resp => { + ).then((resp) => { equal(resp.data.results.length, 1); done(); }); }); }); - it('containedIn queries', function(done) { - const makeBoxedNumber = function(i) { + it('containedIn queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.containedIn('number', [3, 5, 7, 9, 11]); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); done(); }); }); }); - it('containedIn false queries', done => { - const makeBoxedNumber = i => { + it('containedIn false queries', (done) => { + const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; @@ -1322,15 +1322,15 @@ describe('Parse.Query testing', () => { return query.find(); }) .then(done.fail) - .catch(error => { + .catch((error) => { equal(error.code, Parse.Error.INVALID_JSON); equal(error.message, 'bad $in value'); done(); }); }); - it('notContainedIn false queries', done => { - const makeBoxedNumber = i => { + it('notContainedIn false queries', (done) => { + const makeBoxedNumber = (i) => { return new BoxedNumber({ number: i }); }; const numbers = [-3, -2, -1, 0, 1]; @@ -1342,36 +1342,36 @@ describe('Parse.Query testing', () => { return query.find(); }) .then(done.fail) - .catch(error => { + .catch((error) => { equal(error.code, Parse.Error.INVALID_JSON); equal(error.message, 'bad $nin value'); done(); }); }); - it('notContainedIn queries', function(done) { - const makeBoxedNumber = function(i) { + it('notContainedIn queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.notContainedIn('number', [3, 5, 7, 9, 11]); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 6); done(); }); }); }); - it('objectId containedIn queries', function(done) { - const makeBoxedNumber = function(i) { + it('objectId containedIn queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function(list) { + ).then(function (list) { const query = new Parse.Query(BoxedNumber); query.containedIn('objectId', [ list[2].id, @@ -1380,7 +1380,7 @@ describe('Parse.Query testing', () => { 'NONSENSE', ]); query.ascending('number'); - query.find().then(function(results) { + query.find().then(function (results) { if (results.length != 3) { fail('expected 3 results'); } else { @@ -1393,16 +1393,16 @@ describe('Parse.Query testing', () => { }); }); - it('objectId equalTo queries', function(done) { - const makeBoxedNumber = function(i) { + it('objectId equalTo queries', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function(list) { + ).then(function (list) { const query = new Parse.Query(BoxedNumber); query.equalTo('objectId', list[4].id); - query.find().then(function(results) { + query.find().then(function (results) { if (results.length != 1) { fail('expected 1 result'); done(); @@ -1414,40 +1414,40 @@ describe('Parse.Query testing', () => { }); }); - it('find no elements', function(done) { - const makeBoxedNumber = function(i) { + it('find no elements', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.equalTo('number', 17); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 0); done(); }); }); }); - it('find with error', function(done) { + it('find with error', function (done) { const query = new Parse.Query(BoxedNumber); query.equalTo('$foo', 'bar'); query .find() .then(done.fail) - .catch(error => expect(error.code).toBe(Parse.Error.INVALID_KEY_NAME)) + .catch((error) => expect(error.code).toBe(Parse.Error.INVALID_KEY_NAME)) .then(done); }); - it('get', function(done) { - Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function( + it('get', function (done) { + Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function ( items ) { ok(items[0]); const objectId = items[0].id; const query = new Parse.Query(TestObject); - query.get(objectId).then(function(result) { + query.get(objectId).then(function (result) { ok(result); equal(result.id, objectId); equal(result.get('foo'), 'bar'); @@ -1458,8 +1458,8 @@ describe('Parse.Query testing', () => { }); }); - it('get undefined', function(done) { - Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function( + it('get undefined', function (done) { + Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function ( items ) { ok(items[0]); @@ -1468,18 +1468,18 @@ describe('Parse.Query testing', () => { }); }); - it('get error', function(done) { - Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function( + it('get error', function (done) { + Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function ( items ) { ok(items[0]); const query = new Parse.Query(TestObject); query.get('InvalidObjectID').then( - function() { + function () { ok(false, 'The get should have failed.'); done(); }, - function(error) { + function (error) { equal(error.code, Parse.Error.OBJECT_NOT_FOUND); done(); } @@ -1487,49 +1487,49 @@ describe('Parse.Query testing', () => { }); }); - it('first', function(done) { - Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function() { + it('first', function (done) { + Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function () { const query = new Parse.Query(TestObject); query.equalTo('foo', 'bar'); - query.first().then(function(result) { + query.first().then(function (result) { equal(result.get('foo'), 'bar'); done(); }); }); }); - it('first no result', function(done) { - Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function() { + it('first no result', function (done) { + Parse.Object.saveAll([new TestObject({ foo: 'bar' })]).then(function () { const query = new Parse.Query(TestObject); query.equalTo('foo', 'baz'); - query.first().then(function(result) { + query.first().then(function (result) { equal(result, undefined); done(); }); }); }); - it('first with two results', function(done) { + it('first with two results', function (done) { Parse.Object.saveAll([ new TestObject({ foo: 'bar' }), new TestObject({ foo: 'bar' }), - ]).then(function() { + ]).then(function () { const query = new Parse.Query(TestObject); query.equalTo('foo', 'bar'); - query.first().then(function(result) { + query.first().then(function (result) { equal(result.get('foo'), 'bar'); done(); }); }); }); - it('first with error', function(done) { + it('first with error', function (done) { const query = new Parse.Query(BoxedNumber); query.equalTo('$foo', 'bar'); query .first() .then(done.fail) - .catch(e => expect(e.code).toBe(Parse.Error.INVALID_KEY_NAME)) + .catch((e) => expect(e.code).toBe(Parse.Error.INVALID_KEY_NAME)) .then(done); }); @@ -1537,16 +1537,16 @@ describe('Parse.Query testing', () => { className: 'Container', }); - it('notEqualTo object', function(done) { + it('notEqualTo object', function (done) { const item1 = new TestObject(); const item2 = new TestObject(); const container1 = new Container({ item: item1 }); const container2 = new Container({ item: item2 }); Parse.Object.saveAll([item1, item2, container1, container2]).then( - function() { + function () { const query = new Parse.Query(Container); query.notEqualTo('item', item1); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); @@ -1554,63 +1554,67 @@ describe('Parse.Query testing', () => { ); }); - it('skip', function(done) { - Parse.Object.saveAll([new TestObject(), new TestObject()]).then(function() { - const query = new Parse.Query(TestObject); - query.skip(1); - query.find().then(function(results) { - equal(results.length, 1); - query.skip(3); - query.find().then(function(results) { - equal(results.length, 0); - done(); + it('skip', function (done) { + Parse.Object.saveAll([new TestObject(), new TestObject()]).then( + function () { + const query = new Parse.Query(TestObject); + query.skip(1); + query.find().then(function (results) { + equal(results.length, 1); + query.skip(3); + query.find().then(function (results) { + equal(results.length, 0); + done(); + }); }); - }); - }); + } + ); }); - it("skip doesn't affect count", function(done) { - Parse.Object.saveAll([new TestObject(), new TestObject()]).then(function() { - const query = new Parse.Query(TestObject); - query.count().then(function(count) { - equal(count, 2); - query.skip(1); - query.count().then(function(count) { + it("skip doesn't affect count", function (done) { + Parse.Object.saveAll([new TestObject(), new TestObject()]).then( + function () { + const query = new Parse.Query(TestObject); + query.count().then(function (count) { equal(count, 2); - query.skip(3); - query.count().then(function(count) { + query.skip(1); + query.count().then(function (count) { equal(count, 2); - done(); + query.skip(3); + query.count().then(function (count) { + equal(count, 2); + done(); + }); }); }); - }); - }); + } + ); }); - it('count', function(done) { - const makeBoxedNumber = function(i) { + it('count', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; Parse.Object.saveAll( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(makeBoxedNumber) - ).then(function() { + ).then(function () { const query = new Parse.Query(BoxedNumber); query.greaterThan('number', 1); - query.count().then(function(count) { + query.count().then(function (count) { equal(count, 8); done(); }); }); }); - it('order by ascending number', function(done) { - const makeBoxedNumber = function(i) { + it('order by ascending number', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; - Parse.Object.saveAll([3, 1, 2].map(makeBoxedNumber)).then(function() { + Parse.Object.saveAll([3, 1, 2].map(makeBoxedNumber)).then(function () { const query = new Parse.Query(BoxedNumber); query.ascending('number'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 3); equal(results[0].get('number'), 1); equal(results[1].get('number'), 2); @@ -1620,14 +1624,14 @@ describe('Parse.Query testing', () => { }); }); - it('order by descending number', function(done) { - const makeBoxedNumber = function(i) { + it('order by descending number', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; - Parse.Object.saveAll([3, 1, 2].map(makeBoxedNumber)).then(function() { + Parse.Object.saveAll([3, 1, 2].map(makeBoxedNumber)).then(function () { const query = new Parse.Query(BoxedNumber); query.descending('number'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 3); equal(results[0].get('number'), 3); equal(results[1].get('number'), 2); @@ -1637,111 +1641,111 @@ describe('Parse.Query testing', () => { }); }); - it('can order on an object string field', function(done) { + it('can order on an object string field', function (done) { const testSet = [ { sortField: { value: 'Z' } }, { sortField: { value: 'A' } }, { sortField: { value: 'M' } }, ]; - const objects = testSet.map(e => new Parse.Object('Test', e)); + const objects = testSet.map((e) => new Parse.Object('Test', e)); Parse.Object.saveAll(objects) .then(() => new Parse.Query('Test').addDescending('sortField.value').first() ) - .then(result => { + .then((result) => { expect(result.get('sortField').value).toBe('Z'); return new Parse.Query('Test').addAscending('sortField.value').first(); }) - .then(result => { + .then((result) => { expect(result.get('sortField').value).toBe('A'); done(); }) .catch(done.fail); }); - it('can order on an object string field (level 2)', function(done) { + it('can order on an object string field (level 2)', function (done) { const testSet = [ { sortField: { value: { field: 'Z' } } }, { sortField: { value: { field: 'A' } } }, { sortField: { value: { field: 'M' } } }, ]; - const objects = testSet.map(e => new Parse.Object('Test', e)); + const objects = testSet.map((e) => new Parse.Object('Test', e)); Parse.Object.saveAll(objects) .then(() => new Parse.Query('Test').addDescending('sortField.value.field').first() ) - .then(result => { + .then((result) => { expect(result.get('sortField').value.field).toBe('Z'); return new Parse.Query('Test') .addAscending('sortField.value.field') .first(); }) - .then(result => { + .then((result) => { expect(result.get('sortField').value.field).toBe('A'); done(); }) .catch(done.fail); }); - it('can order on an object number field', function(done) { + it('can order on an object number field', function (done) { const testSet = [ { sortField: { value: 10 } }, { sortField: { value: 1 } }, { sortField: { value: 5 } }, ]; - const objects = testSet.map(e => new Parse.Object('Test', e)); + const objects = testSet.map((e) => new Parse.Object('Test', e)); Parse.Object.saveAll(objects) .then(() => new Parse.Query('Test').addDescending('sortField.value').first() ) - .then(result => { + .then((result) => { expect(result.get('sortField').value).toBe(10); return new Parse.Query('Test').addAscending('sortField.value').first(); }) - .then(result => { + .then((result) => { expect(result.get('sortField').value).toBe(1); done(); }) .catch(done.fail); }); - it('can order on an object number field (level 2)', function(done) { + it('can order on an object number field (level 2)', function (done) { const testSet = [ { sortField: { value: { field: 10 } } }, { sortField: { value: { field: 1 } } }, { sortField: { value: { field: 5 } } }, ]; - const objects = testSet.map(e => new Parse.Object('Test', e)); + const objects = testSet.map((e) => new Parse.Object('Test', e)); Parse.Object.saveAll(objects) .then(() => new Parse.Query('Test').addDescending('sortField.value.field').first() ) - .then(result => { + .then((result) => { expect(result.get('sortField').value.field).toBe(10); return new Parse.Query('Test') .addAscending('sortField.value.field') .first(); }) - .then(result => { + .then((result) => { expect(result.get('sortField').value.field).toBe(1); done(); }) .catch(done.fail); }); - it('order by ascending number then descending string', function(done) { + it('order by ascending number then descending string', function (done) { const strings = ['a', 'b', 'c', 'd']; - const makeBoxedNumber = function(num, i) { + const makeBoxedNumber = function (num, i) { return new BoxedNumber({ number: num, string: strings[i] }); }; - Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber)).then(function() { + Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber)).then(function () { const query = new Parse.Query(BoxedNumber); query.ascending('number').addDescending('string'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); equal(results[0].get('number'), 1); equal(results[0].get('string'), 'b'); @@ -1756,9 +1760,9 @@ describe('Parse.Query testing', () => { }); }); - it('order by descending number then ascending string', function(done) { + it('order by descending number then ascending string', function (done) { const strings = ['a', 'b', 'c', 'd']; - const makeBoxedNumber = function(num, i) { + const makeBoxedNumber = function (num, i) { return new BoxedNumber({ number: num, string: strings[i] }); }; @@ -1770,7 +1774,7 @@ describe('Parse.Query testing', () => { return query.find(); }) .then( - results => { + (results) => { equal(results.length, 4); equal(results[0].get('number'), 3); equal(results[0].get('string'), 'a'); @@ -1782,22 +1786,22 @@ describe('Parse.Query testing', () => { equal(results[3].get('string'), 'b'); done(); }, - err => { + (err) => { jfail(err); done(); } ); }); - it('order by descending number and string', function(done) { + it('order by descending number and string', function (done) { const strings = ['a', 'b', 'c', 'd']; - const makeBoxedNumber = function(num, i) { + const makeBoxedNumber = function (num, i) { return new BoxedNumber({ number: num, string: strings[i] }); }; - Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber)).then(function() { + Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber)).then(function () { const query = new Parse.Query(BoxedNumber); query.descending('number,string'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); equal(results[0].get('number'), 3); equal(results[0].get('string'), 'c'); @@ -1812,16 +1816,16 @@ describe('Parse.Query testing', () => { }); }); - it('order by descending number and string, with space', function(done) { + it('order by descending number and string, with space', function (done) { const strings = ['a', 'b', 'c', 'd']; - const makeBoxedNumber = function(num, i) { + const makeBoxedNumber = function (num, i) { return new BoxedNumber({ number: num, string: strings[i] }); }; Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber)).then( - function() { + function () { const query = new Parse.Query(BoxedNumber); query.descending('number, string'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); equal(results[0].get('number'), 3); equal(results[0].get('string'), 'c'); @@ -1834,22 +1838,22 @@ describe('Parse.Query testing', () => { done(); }); }, - err => { + (err) => { jfail(err); done(); } ); }); - it('order by descending number and string, with array arg', function(done) { + it('order by descending number and string, with array arg', function (done) { const strings = ['a', 'b', 'c', 'd']; - const makeBoxedNumber = function(num, i) { + const makeBoxedNumber = function (num, i) { return new BoxedNumber({ number: num, string: strings[i] }); }; - Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber)).then(function() { + Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber)).then(function () { const query = new Parse.Query(BoxedNumber); query.descending(['number', 'string']); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); equal(results[0].get('number'), 3); equal(results[0].get('string'), 'c'); @@ -1864,15 +1868,15 @@ describe('Parse.Query testing', () => { }); }); - it('order by descending number and string, with multiple args', function(done) { + it('order by descending number and string, with multiple args', function (done) { const strings = ['a', 'b', 'c', 'd']; - const makeBoxedNumber = function(num, i) { + const makeBoxedNumber = function (num, i) { return new BoxedNumber({ number: num, string: strings[i] }); }; - Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber)).then(function() { + Parse.Object.saveAll([3, 1, 3, 2].map(makeBoxedNumber)).then(function () { const query = new Parse.Query(BoxedNumber); query.descending('number', 'string'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); equal(results[0].get('number'), 3); equal(results[0].get('string'), 'c'); @@ -1887,23 +1891,23 @@ describe('Parse.Query testing', () => { }); }); - it("can't order by password", function(done) { - const makeBoxedNumber = function(i) { + it("can't order by password", function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; - Parse.Object.saveAll([3, 1, 2].map(makeBoxedNumber)).then(function() { + Parse.Object.saveAll([3, 1, 2].map(makeBoxedNumber)).then(function () { const query = new Parse.Query(BoxedNumber); query.ascending('_password'); query .find() .then(done.fail) - .catch(e => expect(e.code).toBe(Parse.Error.INVALID_KEY_NAME)) + .catch((e) => expect(e.code).toBe(Parse.Error.INVALID_KEY_NAME)) .then(done); }); }); - it('order by _created_at', function(done) { - const makeBoxedNumber = function(i) { + it('order by _created_at', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; const numbers = [3, 1, 2].map(makeBoxedNumber); @@ -1915,10 +1919,10 @@ describe('Parse.Query testing', () => { .then(() => { return numbers[2].save(); }) - .then(function() { + .then(function () { const query = new Parse.Query(BoxedNumber); query.ascending('_created_at'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 3); equal(results[0].get('number'), 3); equal(results[1].get('number'), 1); @@ -1928,8 +1932,8 @@ describe('Parse.Query testing', () => { }); }); - it('order by createdAt', function(done) { - const makeBoxedNumber = function(i) { + it('order by createdAt', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; const numbers = [3, 1, 2].map(makeBoxedNumber); @@ -1941,10 +1945,10 @@ describe('Parse.Query testing', () => { .then(() => { return numbers[2].save(); }) - .then(function() { + .then(function () { const query = new Parse.Query(BoxedNumber); query.descending('createdAt'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 3); equal(results[0].get('number'), 2); equal(results[1].get('number'), 1); @@ -1954,8 +1958,8 @@ describe('Parse.Query testing', () => { }); }); - it('order by _updated_at', function(done) { - const makeBoxedNumber = function(i) { + it('order by _updated_at', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; const numbers = [3, 1, 2].map(makeBoxedNumber); @@ -1967,12 +1971,12 @@ describe('Parse.Query testing', () => { .then(() => { return numbers[2].save(); }) - .then(function() { + .then(function () { numbers[1].set('number', 4); - numbers[1].save().then(function() { + numbers[1].save().then(function () { const query = new Parse.Query(BoxedNumber); query.ascending('_updated_at'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 3); equal(results[0].get('number'), 3); equal(results[1].get('number'), 2); @@ -1983,8 +1987,8 @@ describe('Parse.Query testing', () => { }); }); - it('order by updatedAt', function(done) { - const makeBoxedNumber = function(i) { + it('order by updatedAt', function (done) { + const makeBoxedNumber = function (i) { return new BoxedNumber({ number: i }); }; const numbers = [3, 1, 2].map(makeBoxedNumber); @@ -1996,12 +2000,12 @@ describe('Parse.Query testing', () => { .then(() => { return numbers[2].save(); }) - .then(function() { + .then(function () { numbers[1].set('number', 4); - numbers[1].save().then(function() { + numbers[1].save().then(function () { const query = new Parse.Query(BoxedNumber); query.descending('_updated_at'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 3); equal(results[0].get('number'), 4); equal(results[1].get('number'), 2); @@ -2025,25 +2029,25 @@ describe('Parse.Query testing', () => { const start = new Date(); let one, two, three; return makeTimeObject(start, 1) - .then(o1 => { + .then((o1) => { one = o1; return makeTimeObject(start, 2); }) - .then(o2 => { + .then((o2) => { two = o2; return makeTimeObject(start, 3); }) - .then(o3 => { + .then((o3) => { three = o3; return [one, two, three]; }); } - it('time equality', function(done) { - makeThreeTimeObjects().then(function(list) { + it('time equality', function (done) { + makeThreeTimeObjects().then(function (list) { const query = new Parse.Query(TestObject); query.equalTo('time', list[1].get('time')); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); equal(results[0].get('name'), 'item2'); done(); @@ -2051,11 +2055,11 @@ describe('Parse.Query testing', () => { }); }); - it('time lessThan', function(done) { - makeThreeTimeObjects().then(function(list) { + it('time lessThan', function (done) { + makeThreeTimeObjects().then(function (list) { const query = new Parse.Query(TestObject); query.lessThan('time', list[2].get('time')); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 2); done(); }); @@ -2063,71 +2067,71 @@ describe('Parse.Query testing', () => { }); // This test requires Date objects to be consistently stored as a Date. - it('time createdAt', function(done) { - makeThreeTimeObjects().then(function(list) { + it('time createdAt', function (done) { + makeThreeTimeObjects().then(function (list) { const query = new Parse.Query(TestObject); query.greaterThanOrEqualTo('createdAt', list[0].createdAt); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 3); done(); }); }); }); - it('matches string', function(done) { + it('matches string', function (done) { const thing1 = new TestObject(); thing1.set('myString', 'football'); const thing2 = new TestObject(); thing2.set('myString', 'soccer'); - Parse.Object.saveAll([thing1, thing2]).then(function() { + Parse.Object.saveAll([thing1, thing2]).then(function () { const query = new Parse.Query(TestObject); query.matches('myString', '^fo*\\wb[^o]l+$'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); }); }); - it('matches regex', function(done) { + it('matches regex', function (done) { const thing1 = new TestObject(); thing1.set('myString', 'football'); const thing2 = new TestObject(); thing2.set('myString', 'soccer'); - Parse.Object.saveAll([thing1, thing2]).then(function() { + Parse.Object.saveAll([thing1, thing2]).then(function () { const query = new Parse.Query(TestObject); query.matches('myString', /^fo*\wb[^o]l+$/); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); }); }); - it('case insensitive regex success', function(done) { + it('case insensitive regex success', function (done) { const thing = new TestObject(); thing.set('myString', 'football'); - Parse.Object.saveAll([thing]).then(function() { + Parse.Object.saveAll([thing]).then(function () { const query = new Parse.Query(TestObject); query.matches('myString', 'FootBall', 'i'); query.find().then(done); }); }); - it('regexes with invalid options fail', function(done) { + it('regexes with invalid options fail', function (done) { const query = new Parse.Query(TestObject); query.matches('myString', 'FootBall', 'some invalid option'); query .find() .then(done.fail) - .catch(e => expect(e.code).toBe(Parse.Error.INVALID_QUERY)) + .catch((e) => expect(e.code).toBe(Parse.Error.INVALID_QUERY)) .then(done); }); - it('Use a regex that requires all modifiers', function(done) { + it('Use a regex that requires all modifiers', function (done) { const thing = new TestObject(); thing.set('myString', 'PArSe\nCom'); - Parse.Object.saveAll([thing]).then(function() { + Parse.Object.saveAll([thing]).then(function () { const query = new Parse.Query(TestObject); query.matches( 'myString', @@ -2137,11 +2141,11 @@ describe('Parse.Query testing', () => { 'mixs' ); query.find().then( - function(results) { + function (results) { equal(results.length, 1); done(); }, - function(err) { + function (err) { jfail(err); done(); } @@ -2149,13 +2153,13 @@ describe('Parse.Query testing', () => { }); }); - it('Regular expression constructor includes modifiers inline', function(done) { + it('Regular expression constructor includes modifiers inline', function (done) { const thing = new TestObject(); thing.set('myString', '\n\nbuffer\n\nparse.COM'); - Parse.Object.saveAll([thing]).then(function() { + Parse.Object.saveAll([thing]).then(function () { const query = new Parse.Query(TestObject); query.matches('myString', /parse\.com/im); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); done(); }); @@ -2166,23 +2170,23 @@ describe('Parse.Query testing', () => { "\\E' !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTU" + "VWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'"; - it('contains', function(done) { + it('contains', function (done) { Parse.Object.saveAll([ new TestObject({ myString: 'zax' + someAscii + 'qub' }), new TestObject({ myString: 'start' + someAscii }), new TestObject({ myString: someAscii + 'end' }), new TestObject({ myString: someAscii }), - ]).then(function() { + ]).then(function () { const query = new Parse.Query(TestObject); query.contains('myString', someAscii); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); done(); }); }); }); - it('nested contains', done => { + it('nested contains', (done) => { const sender1 = { group: ['A', 'B'] }; const sender2 = { group: ['A', 'C'] }; const sender3 = { group: ['B', 'C'] }; @@ -2195,45 +2199,45 @@ describe('Parse.Query testing', () => { query.contains('sender.group', 'A'); return query.find(); }) - .then(results => { + .then((results) => { equal(results.length, 2); done(); }, done.fail); }); - it('startsWith', function(done) { + it('startsWith', function (done) { Parse.Object.saveAll([ new TestObject({ myString: 'zax' + someAscii + 'qub' }), new TestObject({ myString: 'start' + someAscii }), new TestObject({ myString: someAscii + 'end' }), new TestObject({ myString: someAscii }), - ]).then(function() { + ]).then(function () { const query = new Parse.Query(TestObject); query.startsWith('myString', someAscii); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 2); done(); }); }); }); - it('endsWith', function(done) { + it('endsWith', function (done) { Parse.Object.saveAll([ new TestObject({ myString: 'zax' + someAscii + 'qub' }), new TestObject({ myString: 'start' + someAscii }), new TestObject({ myString: someAscii + 'end' }), new TestObject({ myString: someAscii }), - ]).then(function() { + ]).then(function () { const query = new Parse.Query(TestObject); query.endsWith('myString', someAscii); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 2); done(); }); }); }); - it('exists', function(done) { + it('exists', function (done) { const objects = []; for (const i of [0, 1, 2, 3, 4, 5, 6, 7, 8]) { const item = new TestObject(); @@ -2244,10 +2248,10 @@ describe('Parse.Query testing', () => { } objects.push(item); } - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(TestObject); query.exists('x'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 5); for (const result of results) { ok(result.get('x')); @@ -2257,7 +2261,7 @@ describe('Parse.Query testing', () => { }); }); - it('doesNotExist', function(done) { + it('doesNotExist', function (done) { const objects = []; for (const i of [0, 1, 2, 3, 4, 5, 6, 7, 8]) { const item = new TestObject(); @@ -2268,10 +2272,10 @@ describe('Parse.Query testing', () => { } objects.push(item); } - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(TestObject); query.doesNotExist('x'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); for (const result of results) { ok(result.get('y')); @@ -2281,7 +2285,7 @@ describe('Parse.Query testing', () => { }); }); - it('exists relation', function(done) { + it('exists relation', function (done) { const objects = []; for (const i of [0, 1, 2, 3, 4, 5, 6, 7, 8]) { const container = new Container(); @@ -2295,10 +2299,10 @@ describe('Parse.Query testing', () => { } objects.push(container); } - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(Container); query.exists('x'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 5); for (const result of results) { ok(result.get('x')); @@ -2308,7 +2312,7 @@ describe('Parse.Query testing', () => { }); }); - it('doesNotExist relation', function(done) { + it('doesNotExist relation', function (done) { const objects = []; for (const i of [0, 1, 2, 3, 4, 5, 6, 7]) { const container = new Container(); @@ -2322,10 +2326,10 @@ describe('Parse.Query testing', () => { } objects.push(container); } - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(Container); query.doesNotExist('x'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); for (const result of results) { ok(result.get('y')); @@ -2335,15 +2339,15 @@ describe('Parse.Query testing', () => { }); }); - it("don't include by default", function(done) { + it("don't include by default", function (done) { const child = new TestObject(); const parent = new Container(); child.set('foo', 'bar'); parent.set('child', child); - Parse.Object.saveAll([child, parent]).then(function() { + Parse.Object.saveAll([child, parent]).then(function () { child._clearServerData(); const query = new Parse.Query(Container); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); const parentAgain = results[0]; const goodURL = Parse.serverURL; @@ -2357,15 +2361,15 @@ describe('Parse.Query testing', () => { }); }); - it('include relation', function(done) { + it('include relation', function (done) { const child = new TestObject(); const parent = new Container(); child.set('foo', 'bar'); parent.set('child', child); - Parse.Object.saveAll([child, parent]).then(function() { + Parse.Object.saveAll([child, parent]).then(function () { const query = new Parse.Query(Container); query.include('child'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); const parentAgain = results[0]; const goodURL = Parse.serverURL; @@ -2379,15 +2383,15 @@ describe('Parse.Query testing', () => { }); }); - it('include relation array', function(done) { + it('include relation array', function (done) { const child = new TestObject(); const parent = new Container(); child.set('foo', 'bar'); parent.set('child', child); - Parse.Object.saveAll([child, parent]).then(function() { + Parse.Object.saveAll([child, parent]).then(function () { const query = new Parse.Query(Container); query.include(['child']); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); const parentAgain = results[0]; const goodURL = Parse.serverURL; @@ -2401,7 +2405,7 @@ describe('Parse.Query testing', () => { }); }); - it('nested include', function(done) { + it('nested include', function (done) { const Child = Parse.Object.extend('Child'); const Parent = Parse.Object.extend('Parent'); const Grandparent = Parse.Object.extend('Grandparent'); @@ -2419,27 +2423,21 @@ describe('Parse.Query testing', () => { objects.push(grandparent); } - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(Grandparent); query.include(['parent.child']); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 5); for (const object of results) { equal(object.get('z'), object.get('parent').get('y')); - equal( - object.get('z'), - object - .get('parent') - .get('child') - .get('x') - ); + equal(object.get('z'), object.get('parent').get('child').get('x')); } done(); }); }); }); - it("include doesn't make dirty wrong", function(done) { + it("include doesn't make dirty wrong", function (done) { const Parent = Parse.Object.extend('ParentObject'); const Child = Parse.Object.extend('ChildObject'); const parent = new Parent(); @@ -2447,10 +2445,10 @@ describe('Parse.Query testing', () => { child.set('foo', 'bar'); parent.set('child', child); - Parse.Object.saveAll([child, parent]).then(function() { + Parse.Object.saveAll([child, parent]).then(function () { const query = new Parse.Query(Parent); query.include('child'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); const parentAgain = results[0]; const childAgain = parentAgain.get('child'); @@ -2464,7 +2462,7 @@ describe('Parse.Query testing', () => { }); }); - it('properly includes array', done => { + it('properly includes array', (done) => { const objects = []; let total = 0; while (objects.length != 5) { @@ -2485,12 +2483,12 @@ describe('Parse.Query testing', () => { return query.find(); }) .then( - results => { + (results) => { expect(results.length).toBe(1); const res = results[0]; const objects = res.get('objects'); expect(objects.length).toBe(5); - objects.forEach(object => { + objects.forEach((object) => { total -= object.get('key'); }); expect(total).toBe(0); @@ -2503,7 +2501,7 @@ describe('Parse.Query testing', () => { ); }); - it('properly includes array of mixed objects', done => { + it('properly includes array of mixed objects', (done) => { const objects = []; let total = 0; while (objects.length != 5) { @@ -2530,18 +2528,18 @@ describe('Parse.Query testing', () => { return query.find(); }) .then( - results => { + (results) => { expect(results.length).toBe(1); const res = results[0]; const objects = res.get('objects'); expect(objects.length).toBe(10); - objects.forEach(object => { + objects.forEach((object) => { total -= object.get('key'); }); expect(total).toBe(0); done(); }, - e => { + (e) => { fail('should not fail'); fail(JSON.stringify(e)); done(); @@ -2549,7 +2547,7 @@ describe('Parse.Query testing', () => { ); }); - it('properly nested array of mixed objects with bad ids', done => { + it('properly nested array of mixed objects with bad ids', (done) => { const objects = []; let total = 0; while (objects.length != 5) { @@ -2581,18 +2579,18 @@ describe('Parse.Query testing', () => { return query.find(); }) .then( - results => { + (results) => { expect(results.length).toBe(1); const res = results[0]; const objects = res.get('objects'); expect(objects.length).toBe(5); - objects.forEach(object => { + objects.forEach((object) => { total -= object.get('key'); }); expect(total).toBe(0); done(); }, - err => { + (err) => { jfail(err); fail('should not fail'); done(); @@ -2600,7 +2598,7 @@ describe('Parse.Query testing', () => { ); }); - it('properly fetches nested pointers', done => { + it('properly fetches nested pointers', (done) => { const color = new Parse.Object('Color'); color.set('hex', '#133733'); const circle = new Parse.Object('Circle'); @@ -2621,16 +2619,13 @@ describe('Parse.Query testing', () => { return q.find(); }) .then( - results => { + (results) => { expect(results.length).toBe(1); const figure = results[0]; expect(figure.get('consistsOf').length).toBe(1); - expect( - figure - .get('consistsOf')[0] - .get('color') - .get('hex') - ).toBe('#133733'); + expect(figure.get('consistsOf')[0].get('color').get('hex')).toBe( + '#133733' + ); done(); }, () => { @@ -2640,11 +2635,11 @@ describe('Parse.Query testing', () => { ); }); - it('result object creation uses current extension', function(done) { + it('result object creation uses current extension', function (done) { const ParentObject = Parse.Object.extend({ className: 'ParentObject' }); // Add a foo() method to ChildObject. let ChildObject = Parse.Object.extend('ChildObject', { - foo: function() { + foo: function () { return 'foo'; }, }); @@ -2652,17 +2647,17 @@ describe('Parse.Query testing', () => { const parent = new ParentObject(); const child = new ChildObject(); parent.set('child', child); - Parse.Object.saveAll([child, parent]).then(function() { + Parse.Object.saveAll([child, parent]).then(function () { // Add a bar() method to ChildObject. ChildObject = Parse.Object.extend('ChildObject', { - bar: function() { + bar: function () { return 'bar'; }, }); const query = new Parse.Query(ParentObject); query.include('child'); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 1); const parentAgain = results[0]; const childAgain = parentAgain.get('child'); @@ -2673,7 +2668,7 @@ describe('Parse.Query testing', () => { }); }); - it('matches query', function(done) { + it('matches query', function (done) { const ParentObject = Parse.Object.extend('ParentObject'); const ChildObject = Parse.Object.extend('ChildObject'); const objects = []; @@ -2685,19 +2680,19 @@ describe('Parse.Query testing', () => { }) ); } - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const subQuery = new Parse.Query(ChildObject); subQuery.greaterThan('x', 5); const query = new Parse.Query(ParentObject); query.matchesQuery('child', subQuery); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 4); for (const object of results) { ok(object.get('x') > 15); } const query = new Parse.Query(ParentObject); query.doesNotMatchQuery('child', subQuery); - query.find().then(function(results) { + query.find().then(function (results) { equal(results.length, 6); for (const object of results) { ok(object.get('x') >= 10); @@ -2709,7 +2704,7 @@ describe('Parse.Query testing', () => { }); }); - it('select query', function(done) { + it('select query', function (done) { const RestaurantObject = Parse.Object.extend('Restaurant'); const PersonObject = Parse.Object.extend('Person'); const objects = [ @@ -2720,12 +2715,12 @@ describe('Parse.Query testing', () => { new PersonObject({ name: 'Billy', hometown: 'Detroit' }), ]; - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(RestaurantObject); query.greaterThan('ratings', 4); const mainQuery = new Parse.Query(PersonObject); mainQuery.matchesKeyInQuery('hometown', 'location', query); - mainQuery.find().then(function(results) { + mainQuery.find().then(function (results) { equal(results.length, 1); equal(results[0].get('name'), 'Bob'); done(); @@ -2733,7 +2728,7 @@ describe('Parse.Query testing', () => { }); }); - it('$select inside $or', done => { + it('$select inside $or', (done) => { const Restaurant = Parse.Object.extend('Restaurant'); const Person = Parse.Object.extend('Person'); const objects = [ @@ -2756,19 +2751,19 @@ describe('Parse.Query testing', () => { return query.find(); }) .then( - results => { + (results) => { expect(results.length).toEqual(2); done(); }, - error => { + (error) => { jfail(error); done(); } ); }); - it('$nor valid query', done => { - const objects = Array.from(Array(10).keys()).map(rating => { + it('$nor valid query', (done) => { + const objects = Array.from(Array(10).keys()).map((rating) => { return new TestObject({ rating: rating }); }); @@ -2794,19 +2789,19 @@ describe('Parse.Query testing', () => { ) ); }) - .then(response => { + .then((response) => { const results = response.data; expect(results.results.length).toBe(highValue - lowValue); expect( results.results.every( - res => res.rating > lowValue && res.rating <= highValue + (res) => res.rating > lowValue && res.rating <= highValue ) ).toBe(true); done(); }); }); - it('$nor invalid query - empty array', done => { + it('$nor invalid query - empty array', (done) => { const options = Object.assign({}, masterKeyOptions, { qs: { where: JSON.stringify({ $nor: [] }), @@ -2824,13 +2819,13 @@ describe('Parse.Query testing', () => { ); }) .then(done.fail) - .catch(response => { + .catch((response) => { equal(response.data.code, Parse.Error.INVALID_QUERY); done(); }); }); - it('$nor invalid query - wrong type', done => { + it('$nor invalid query - wrong type', (done) => { const options = Object.assign({}, masterKeyOptions, { qs: { where: JSON.stringify({ $nor: 1337 }), @@ -2848,13 +2843,13 @@ describe('Parse.Query testing', () => { ); }) .then(done.fail) - .catch(response => { + .catch((response) => { equal(response.data.code, Parse.Error.INVALID_QUERY); done(); }); }); - it('dontSelect query', function(done) { + it('dontSelect query', function (done) { const RestaurantObject = Parse.Object.extend('Restaurant'); const PersonObject = Parse.Object.extend('Person'); const objects = [ @@ -2865,12 +2860,12 @@ describe('Parse.Query testing', () => { new PersonObject({ name: 'Billy', hometown: 'Djibouti' }), ]; - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(RestaurantObject); query.greaterThan('ratings', 4); const mainQuery = new Parse.Query(PersonObject); mainQuery.doesNotMatchKeyInQuery('hometown', 'location', query); - mainQuery.find().then(function(results) { + mainQuery.find().then(function (results) { equal(results.length, 1); equal(results[0].get('name'), 'Tom'); done(); @@ -2878,7 +2873,7 @@ describe('Parse.Query testing', () => { }); }); - it('dontSelect query without conditions', function(done) { + it('dontSelect query without conditions', function (done) { const RestaurantObject = Parse.Object.extend('Restaurant'); const PersonObject = Parse.Object.extend('Person'); const objects = [ @@ -2889,11 +2884,11 @@ describe('Parse.Query testing', () => { new PersonObject({ name: 'Billy', hometown: 'Ouagadougou' }), ]; - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(RestaurantObject); const mainQuery = new Parse.Query(PersonObject); mainQuery.doesNotMatchKeyInQuery('hometown', 'location', query); - mainQuery.find().then(results => { + mainQuery.find().then((results) => { equal(results.length, 1); equal(results[0].get('name'), 'Tom'); done(); @@ -2901,7 +2896,7 @@ describe('Parse.Query testing', () => { }); }); - it('equalTo on same column as $dontSelect should not break $dontSelect functionality (#3678)', function(done) { + it('equalTo on same column as $dontSelect should not break $dontSelect functionality (#3678)', function (done) { const AuthorObject = Parse.Object.extend('Author'); const BlockedObject = Parse.Object.extend('Blocked'); const PostObject = Parse.Object.extend('Post'); @@ -2911,11 +2906,11 @@ describe('Parse.Query testing', () => { return new AuthorObject({ name: 'Julius' }) .save() - .then(user => { + .then((user) => { postAuthor = user; return new AuthorObject({ name: 'Bob' }).save(); }) - .then(user => { + .then((user) => { requestUser = user; const objects = [ new PostObject({ author: postAuthor, title: 'Lorem ipsum' }), @@ -2936,14 +2931,14 @@ describe('Parse.Query testing', () => { .equalTo('author', postAuthor) .doesNotMatchKeyInQuery('author', 'blockedBy', banListQuery) .find() - .then(r => { + .then((r) => { expect(r.length).toEqual(0); done(); }, done.fail); }); }); - it('multiple dontSelect query', function(done) { + it('multiple dontSelect query', function (done) { const RestaurantObject = Parse.Object.extend('Restaurant'); const PersonObject = Parse.Object.extend('Person'); const objects = [ @@ -2955,7 +2950,7 @@ describe('Parse.Query testing', () => { new PersonObject({ name: 'Tom', hometown: 'Ouagadougou' }), ]; - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query = new Parse.Query(RestaurantObject); query.greaterThan('ratings', 6); const query2 = new Parse.Query(RestaurantObject); @@ -2970,7 +2965,7 @@ describe('Parse.Query testing', () => { 'objectId', Parse.Query.or(subQuery, subQuery2) ); - mainQuery.find().then(function(results) { + mainQuery.find().then(function (results) { equal(results.length, 1); equal(results[0].get('name'), 'Bob'); done(); @@ -2978,45 +2973,45 @@ describe('Parse.Query testing', () => { }); }); - it('object with length', function(done) { + it('object with length', function (done) { const TestObject = Parse.Object.extend('TestObject'); const obj = new TestObject(); obj.set('length', 5); equal(obj.get('length'), 5); obj.save().then( - function() { + function () { const query = new Parse.Query(TestObject); query.find().then( - function(results) { + function (results) { equal(results.length, 1); equal(results[0].get('length'), 5); done(); }, - function(error) { + function (error) { ok(false, error.message); done(); } ); }, - function(error) { + function (error) { ok(false, error.message); done(); } ); }); - it('include user', function(done) { - Parse.User.signUp('bob', 'password', { age: 21 }).then(function(user) { + it('include user', function (done) { + Parse.User.signUp('bob', 'password', { age: 21 }).then(function (user) { const TestObject = Parse.Object.extend('TestObject'); const obj = new TestObject(); obj .save({ owner: user, }) - .then(function(obj) { + .then(function (obj) { const query = new Parse.Query(TestObject); query.include('owner'); - query.get(obj.id).then(function(objAgain) { + query.get(obj.id).then(function (objAgain) { equal(objAgain.id, obj.id); ok(objAgain.get('owner') instanceof Parse.User); equal(objAgain.get('owner').get('age'), 21); @@ -3026,19 +3021,19 @@ describe('Parse.Query testing', () => { }, done.fail); }); - it('or queries', function(done) { - const objects = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function(x) { + it('or queries', function (done) { + const objects = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function (x) { const object = new Parse.Object('BoxedNumber'); object.set('x', x); return object; }); - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const query1 = new Parse.Query('BoxedNumber'); query1.lessThan('x', 2); const query2 = new Parse.Query('BoxedNumber'); query2.greaterThan('x', 5); const orQuery = Parse.Query.or(query1, query2); - orQuery.find().then(function(results) { + orQuery.find().then(function (results) { equal(results.length, 6); for (const number of results) { ok(number.get('x') < 2 || number.get('x') > 5); @@ -3049,8 +3044,8 @@ describe('Parse.Query testing', () => { }); // This relies on matchesQuery aka the $inQuery operator - it('or complex queries', function(done) { - const objects = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function(x) { + it('or complex queries', function (done) { + const objects = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function (x) { const child = new Parse.Object('Child'); child.set('x', x); const parent = new Parse.Object('Parent'); @@ -3059,7 +3054,7 @@ describe('Parse.Query testing', () => { return parent; }); - Parse.Object.saveAll(objects).then(function() { + Parse.Object.saveAll(objects).then(function () { const subQuery = new Parse.Query('Child'); subQuery.equalTo('x', 4); const query1 = new Parse.Query('Parent'); @@ -3067,75 +3062,75 @@ describe('Parse.Query testing', () => { const query2 = new Parse.Query('Parent'); query2.lessThan('y', 2); const orQuery = Parse.Query.or(query1, query2); - orQuery.find().then(function(results) { + orQuery.find().then(function (results) { equal(results.length, 3); done(); }); }); }); - it('async methods', function(done) { - const saves = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function(x) { + it('async methods', function (done) { + const saves = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function (x) { const obj = new Parse.Object('TestObject'); obj.set('x', x + 1); return obj.save(); }); Promise.all(saves) - .then(function() { + .then(function () { const query = new Parse.Query('TestObject'); query.ascending('x'); return query.first(); }) - .then(function(obj) { + .then(function (obj) { equal(obj.get('x'), 1); const query = new Parse.Query('TestObject'); query.descending('x'); return query.find(); }) - .then(function(results) { + .then(function (results) { equal(results.length, 10); const query = new Parse.Query('TestObject'); return query.get(results[0].id); }) - .then(function(obj1) { + .then(function (obj1) { equal(obj1.get('x'), 10); const query = new Parse.Query('TestObject'); return query.count(); }) - .then(function(count) { + .then(function (count) { equal(count, 10); }) - .then(function() { + .then(function () { done(); }); }); - it('query.each', function(done) { + it('query.each', function (done) { const TOTAL = 50; const COUNT = 25; - const items = range(TOTAL).map(function(x) { + const items = range(TOTAL).map(function (x) { const obj = new TestObject(); obj.set('x', x); return obj; }); - Parse.Object.saveAll(items).then(function() { + Parse.Object.saveAll(items).then(function () { const query = new Parse.Query(TestObject); query.lessThan('x', COUNT); const seen = []; query .each( - function(obj) { + function (obj) { seen[obj.get('x')] = (seen[obj.get('x')] || 0) + 1; }, { batchSize: 10, } ) - .then(function() { + .then(function () { equal(seen.length, COUNT); for (let i = 0; i < COUNT; i++) { equal(seen[i], 1, 'Should have seen object number ' + i); @@ -3145,13 +3140,13 @@ describe('Parse.Query testing', () => { }); }); - it('query.each async', function(done) { + it('query.each async', function (done) { const TOTAL = 50; const COUNT = 25; expect(COUNT + 1); - const items = range(TOTAL).map(function(x) { + const items = range(TOTAL).map(function (x) { const obj = new TestObject(); obj.set('x', x); return obj; @@ -3160,13 +3155,13 @@ describe('Parse.Query testing', () => { const seen = []; Parse.Object.saveAll(items) - .then(function() { + .then(function () { const query = new Parse.Query(TestObject); query.lessThan('x', COUNT); return query.each( - function(obj) { - return new Promise(resolve => { - process.nextTick(function() { + function (obj) { + return new Promise((resolve) => { + process.nextTick(function () { seen[obj.get('x')] = (seen[obj.get('x')] || 0) + 1; resolve(); }); @@ -3177,7 +3172,7 @@ describe('Parse.Query testing', () => { } ); }) - .then(function() { + .then(function () { equal(seen.length, COUNT); for (let i = 0; i < COUNT; i++) { equal(seen[i], 1, 'Should have seen object number ' + i); @@ -3186,11 +3181,11 @@ describe('Parse.Query testing', () => { }); }); - it('query.each fails with order', function(done) { + it('query.each fails with order', function (done) { const TOTAL = 50; const COUNT = 25; - const items = range(TOTAL).map(function(x) { + const items = range(TOTAL).map(function (x) { const obj = new TestObject(); obj.set('x', x); return obj; @@ -3199,30 +3194,30 @@ describe('Parse.Query testing', () => { const seen = []; Parse.Object.saveAll(items) - .then(function() { + .then(function () { const query = new Parse.Query(TestObject); query.lessThan('x', COUNT); query.ascending('x'); - return query.each(function(obj) { + return query.each(function (obj) { seen[obj.get('x')] = (seen[obj.get('x')] || 0) + 1; }); }) .then( - function() { + function () { ok(false, 'This should have failed.'); done(); }, - function() { + function () { done(); } ); }); - it('query.each fails with skip', function(done) { + it('query.each fails with skip', function (done) { const TOTAL = 50; const COUNT = 25; - const items = range(TOTAL).map(function(x) { + const items = range(TOTAL).map(function (x) { const obj = new TestObject(); obj.set('x', x); return obj; @@ -3231,32 +3226,32 @@ describe('Parse.Query testing', () => { const seen = []; Parse.Object.saveAll(items) - .then(function() { + .then(function () { const query = new Parse.Query(TestObject); query.lessThan('x', COUNT); query.skip(5); - return query.each(function(obj) { + return query.each(function (obj) { seen[obj.get('x')] = (seen[obj.get('x')] || 0) + 1; }); }) .then( - function() { + function () { ok(false, 'This should have failed.'); done(); }, - function() { + function () { done(); } ); }); - it('query.each fails with limit', function(done) { + it('query.each fails with limit', function (done) { const TOTAL = 50; const COUNT = 25; expect(0); - const items = range(TOTAL).map(function(x) { + const items = range(TOTAL).map(function (x) { const obj = new TestObject(); obj.set('x', x); return obj; @@ -3265,37 +3260,37 @@ describe('Parse.Query testing', () => { const seen = []; Parse.Object.saveAll(items) - .then(function() { + .then(function () { const query = new Parse.Query(TestObject); query.lessThan('x', COUNT); query.limit(5); - return query.each(function(obj) { + return query.each(function (obj) { seen[obj.get('x')] = (seen[obj.get('x')] || 0) + 1; }); }) .then( - function() { + function () { ok(false, 'This should have failed.'); done(); }, - function() { + function () { done(); } ); }); - it('select keys query', function(done) { + it('select keys query', function (done) { const obj = new TestObject({ foo: 'baz', bar: 1 }); obj .save() - .then(function() { + .then(function () { obj._clearServerData(); const query = new Parse.Query(TestObject); query.select('foo'); return query.first(); }) - .then(function(result) { + .then(function (result) { ok(result.id, 'expected object id to be set'); ok(result.createdAt, 'expected object createdAt to be set'); ok(result.updatedAt, 'expected object updatedAt to be set'); @@ -3308,17 +3303,17 @@ describe('Parse.Query testing', () => { ); return result.fetch(); }) - .then(function(result) { + .then(function (result) { strictEqual(result.get('foo'), 'baz'); strictEqual(result.get('bar'), 1); }) - .then(function() { + .then(function () { obj._clearServerData(); const query = new Parse.Query(TestObject); query.select([]); return query.first(); }) - .then(function(result) { + .then(function (result) { ok(result.id, 'expected object id to be set'); ok(!result.dirty(), 'expected result not to be dirty'); strictEqual( @@ -3332,35 +3327,35 @@ describe('Parse.Query testing', () => { "expected 'bar' field to be unset" ); }) - .then(function() { + .then(function () { obj._clearServerData(); const query = new Parse.Query(TestObject); query.select(['foo', 'bar']); return query.first(); }) - .then(function(result) { + .then(function (result) { ok(result.id, 'expected object id to be set'); ok(!result.dirty(), 'expected result not to be dirty'); strictEqual(result.get('foo'), 'baz'); strictEqual(result.get('bar'), 1); }) - .then(function() { + .then(function () { obj._clearServerData(); const query = new Parse.Query(TestObject); query.select('foo', 'bar'); return query.first(); }) - .then(function(result) { + .then(function (result) { ok(result.id, 'expected object id to be set'); ok(!result.dirty(), 'expected result not to be dirty'); strictEqual(result.get('foo'), 'baz'); strictEqual(result.get('bar'), 1); }) .then( - function() { + function () { done(); }, - function(err) { + function (err) { ok(false, 'other error: ' + JSON.stringify(err)); done(); } @@ -3483,15 +3478,15 @@ describe('Parse.Query testing', () => { expect(response.data.results[0].hello).toBe('world'); }); - it('select keys with each query', function(done) { + it('select keys with each query', function (done) { const obj = new TestObject({ foo: 'baz', bar: 1 }); - obj.save().then(function() { + obj.save().then(function () { obj._clearServerData(); const query = new Parse.Query(TestObject); query.select('foo'); query - .each(function(result) { + .each(function (result) { ok(result.id, 'expected object id to be set'); ok(result.createdAt, 'expected object createdAt to be set'); ok(result.updatedAt, 'expected object updatedAt to be set'); @@ -3504,10 +3499,10 @@ describe('Parse.Query testing', () => { ); }) .then( - function() { + function () { done(); }, - function(err) { + function (err) { jfail(err); done(); } @@ -3515,12 +3510,12 @@ describe('Parse.Query testing', () => { }); }); - it('notEqual with array of pointers', done => { + it('notEqual with array of pointers', (done) => { const children = []; const parents = []; const promises = []; for (let i = 0; i < 2; i++) { - const proc = iter => { + const proc = (iter) => { const child = new Parse.Object('Child'); children.push(child); const parent = new Parse.Object('Parent'); @@ -3540,18 +3535,18 @@ describe('Parse.Query testing', () => { query.notEqualTo('child', children[0]); return query.find(); }) - .then(results => { + .then((results) => { expect(results.length).toEqual(1); expect(results[0].id).toEqual(parents[1].id); done(); }) - .catch(error => { + .catch((error) => { console.log(error); }); }); // PG don't support creating a null column - it_exclude_dbs(['postgres'])('querying for null value', done => { + it_exclude_dbs(['postgres'])('querying for null value', (done) => { const obj = new Parse.Object('TestObject'); obj.set('aNull', null); obj @@ -3561,17 +3556,17 @@ describe('Parse.Query testing', () => { query.equalTo('aNull', null); return query.find(); }) - .then(results => { + .then((results) => { expect(results.length).toEqual(1); expect(results[0].get('aNull')).toEqual(null); done(); }); }); - it('query within dictionary', done => { + it('query within dictionary', (done) => { const promises = []; for (let i = 0; i < 2; i++) { - const proc = iter => { + const proc = (iter) => { const obj = new Parse.Object('TestObject'); obj.set('aDict', { x: iter + 1, y: iter + 2 }); promises.push(obj.save()); @@ -3585,17 +3580,17 @@ describe('Parse.Query testing', () => { return query.find(); }) .then( - results => { + (results) => { expect(results.length).toEqual(1); done(); }, - error => { + (error) => { console.log(error); } ); }); - it('supports include on the wrong key type (#2262)', function(done) { + it('supports include on the wrong key type (#2262)', function (done) { const childObject = new Parse.Object('TestChildObject'); childObject.set('hello', 'world'); childObject @@ -3615,7 +3610,7 @@ describe('Parse.Query testing', () => { return q.find(); }) .then( - objs => { + (objs) => { expect(objs.length).toBe(1); expect(objs[0].get('child').get('hello')).toEqual('world'); expect(objs[0].createdAt instanceof Date).toBe(true); @@ -3628,7 +3623,7 @@ describe('Parse.Query testing', () => { ); }); - it('query match on array with single object', done => { + it('query match on array with single object', (done) => { const target = { __type: 'Pointer', className: 'TestObject', @@ -3644,17 +3639,17 @@ describe('Parse.Query testing', () => { return query.find(); }) .then( - results => { + (results) => { expect(results.length).toEqual(1); done(); }, - error => { + (error) => { console.log(error); } ); }); - it('query match on array with multiple objects', done => { + it('query match on array with multiple objects', (done) => { const target1 = { __type: 'Pointer', className: 'TestObject', @@ -3675,17 +3670,17 @@ describe('Parse.Query testing', () => { return query.find(); }) .then( - results => { + (results) => { expect(results.length).toEqual(1); done(); }, - error => { + (error) => { console.log(error); } ); }); - it('query should not match on array when searching for null', done => { + it('query should not match on array when searching for null', (done) => { const target = { __type: 'Pointer', className: 'TestObject', @@ -3703,18 +3698,18 @@ describe('Parse.Query testing', () => { return query.find(); }) .then( - results => { + (results) => { expect(results.length).toEqual(0); done(); }, - error => { + (error) => { console.log(error); } ); }); // #371 - it('should properly interpret a query v1', done => { + it('should properly interpret a query v1', (done) => { const query = new Parse.Query('C1'); const auxQuery = new Parse.Query('C1'); query.matchesKeyInQuery('A1', 'A2', auxQuery); @@ -3724,7 +3719,7 @@ describe('Parse.Query testing', () => { () => { done(); }, - err => { + (err) => { jfail(err); fail('should not failt'); done(); @@ -3732,13 +3727,13 @@ describe('Parse.Query testing', () => { ); }); - it('should properly interpret a query v2', done => { + it('should properly interpret a query v2', (done) => { const user = new Parse.User(); user.set('username', 'foo'); user.set('password', 'bar'); return user .save() - .then(user => { + .then((user) => { const objIdQuery = new Parse.Query('_User').equalTo( 'objectId', user.id @@ -3785,7 +3780,7 @@ describe('Parse.Query testing', () => { () => { done(); }, - err => { + (err) => { jfail(err); fail('should not fail'); done(); @@ -3793,14 +3788,14 @@ describe('Parse.Query testing', () => { ); }); - it('should match a key in an array (#3195)', function(done) { + it('should match a key in an array (#3195)', function (done) { const AuthorObject = Parse.Object.extend('Author'); const GroupObject = Parse.Object.extend('Group'); const PostObject = Parse.Object.extend('Post'); return new AuthorObject() .save() - .then(user => { + .then((user) => { const post = new PostObject({ author: user, }); @@ -3811,12 +3806,12 @@ describe('Parse.Query testing', () => { return Promise.all([post.save(), group.save()]); }) - .then(results => { + .then((results) => { const p = results[0]; return new Parse.Query(PostObject) .matchesKeyInQuery('author', 'members', new Parse.Query(GroupObject)) .find() - .then(r => { + .then((r) => { expect(r.length).toEqual(1); if (r.length > 0) { expect(r[0].id).toEqual(p.id); @@ -3826,7 +3821,7 @@ describe('Parse.Query testing', () => { }); }); - it('should find objects with array of pointers', done => { + it('should find objects with array of pointers', (done) => { const objects = []; while (objects.length != 5) { const object = new Parse.Object('ContainedObject'); @@ -3835,9 +3830,9 @@ describe('Parse.Query testing', () => { } Parse.Object.saveAll(objects) - .then(objects => { + .then((objects) => { const container = new Parse.Object('Container'); - const pointers = objects.map(obj => { + const pointers = objects.map((obj) => { return { __type: 'Pointer', className: 'ContainedObject', @@ -3856,37 +3851,37 @@ describe('Parse.Query testing', () => { query.matchesQuery('objects', inQuery); return query.find(); }) - .then(results => { + .then((results) => { if (results) { expect(results.length).toBe(2); } done(); }) - .catch(err => { + .catch((err) => { jfail(err); fail('should not fail'); done(); }); }); - it('query with two OR subqueries (regression test #1259)', done => { + it('query with two OR subqueries (regression test #1259)', (done) => { const relatedObject = new Parse.Object('Class2'); relatedObject .save() - .then(relatedObject => { + .then((relatedObject) => { const anObject = new Parse.Object('Class1'); const relation = anObject.relation('relation'); relation.add(relatedObject); return anObject.save(); }) - .then(anObject => { + .then((anObject) => { const q1 = anObject.relation('relation').query(); q1.doesNotExist('nonExistantKey1'); const q2 = anObject.relation('relation').query(); q2.doesNotExist('nonExistantKey2'); Parse.Query.or(q1, q2) .find() - .then(results => { + .then((results) => { expect(results.length).toEqual(1); if (results.length == 1) { expect(results[0].objectId).toEqual(q1.objectId); @@ -3896,11 +3891,11 @@ describe('Parse.Query testing', () => { }); }); - it('objectId containedIn with multiple large array', done => { + it('objectId containedIn with multiple large array', (done) => { const obj = new Parse.Object('MyClass'); obj .save() - .then(obj => { + .then((obj) => { const longListOfStrings = []; for (let i = 0; i < 130; i++) { longListOfStrings.push(i.toString()); @@ -3911,13 +3906,13 @@ describe('Parse.Query testing', () => { q.containedIn('objectId', longListOfStrings); return q.find(); }) - .then(results => { + .then((results) => { expect(results.length).toEqual(1); done(); }); }); - it('containedIn with pointers should work with string array', done => { + it('containedIn with pointers should work with string array', (done) => { const obj = new Parse.Object('MyClass'); const child = new Parse.Object('Child'); child @@ -3938,14 +3933,14 @@ describe('Parse.Query testing', () => { query.containedIn('child', [child.id]); return query.find(); }) - .then(results => { + .then((results) => { expect(results.length).toBe(1); }) .then(done) .catch(done.fail); }); - it('containedIn with pointers should work with string array, with many objects', done => { + it('containedIn with pointers should work with string array, with many objects', (done) => { const objs = []; const children = []; for (let i = 0; i < 10; i++) { @@ -3965,29 +3960,29 @@ describe('Parse.Query testing', () => { }) .then(() => { const query = new Parse.Query('MyClass'); - const subset = children.slice(0, 5).map(child => { + const subset = children.slice(0, 5).map((child) => { return child.id; }); query.containedIn('child', subset); return query.find(); }) - .then(results => { + .then((results) => { expect(results.length).toBe(5); }) .then(done) .catch(done.fail); }); - it('include for specific object', function(done) { + it('include for specific object', function (done) { const child = new Parse.Object('Child'); const parent = new Parse.Object('Parent'); child.set('foo', 'bar'); parent.set('child', child); - Parse.Object.saveAll([child, parent]).then(function(response) { + Parse.Object.saveAll([child, parent]).then(function (response) { const savedParent = response[1]; const parentQuery = new Parse.Query('Parent'); parentQuery.include('child'); - parentQuery.get(savedParent.id).then(function(parentObj) { + parentQuery.get(savedParent.id).then(function (parentObj) { const childPointer = parentObj.get('child'); ok(childPointer); equal(childPointer.get('foo'), 'bar'); @@ -3996,14 +3991,14 @@ describe('Parse.Query testing', () => { }); }); - it('select keys for specific object', function(done) { + it('select keys for specific object', function (done) { const Foobar = new Parse.Object('Foobar'); Foobar.set('foo', 'bar'); Foobar.set('fizz', 'buzz'); - Foobar.save().then(function(savedFoobar) { + Foobar.save().then(function (savedFoobar) { const foobarQuery = new Parse.Query('Foobar'); foobarQuery.select('fizz'); - foobarQuery.get(savedFoobar.id).then(function(foobarObj) { + foobarQuery.get(savedFoobar.id).then(function (foobarObj) { equal(foobarObj.get('fizz'), 'buzz'); equal(foobarObj.get('foo'), undefined); done(); @@ -4011,7 +4006,7 @@ describe('Parse.Query testing', () => { }); }); - it('select nested keys (issue #1567)', function(done) { + it('select nested keys (issue #1567)', function (done) { const Foobar = new Parse.Object('Foobar'); const BarBaz = new Parse.Object('Barbaz'); BarBaz.set('key', 'value'); @@ -4023,11 +4018,11 @@ describe('Parse.Query testing', () => { Foobar.set('barBaz', BarBaz); return Foobar.save(); }) - .then(function(savedFoobar) { + .then(function (savedFoobar) { const foobarQuery = new Parse.Query('Foobar'); foobarQuery.include('barBaz'); foobarQuery.select(['fizz', 'barBaz.key']); - foobarQuery.get(savedFoobar.id).then(function(foobarObj) { + foobarQuery.get(savedFoobar.id).then(function (foobarObj) { equal(foobarObj.get('fizz'), 'buzz'); equal(foobarObj.get('foo'), undefined); if (foobarObj.has('barBaz')) { @@ -4041,7 +4036,7 @@ describe('Parse.Query testing', () => { }); }); - it('select nested keys 2 level (issue #1567)', function(done) { + it('select nested keys 2 level (issue #1567)', function (done) { const Foobar = new Parse.Object('Foobar'); const BarBaz = new Parse.Object('Barbaz'); const Bazoo = new Parse.Object('Bazoo'); @@ -4061,29 +4056,20 @@ describe('Parse.Query testing', () => { Foobar.set('barBaz', BarBaz); return Foobar.save(); }) - .then(function(savedFoobar) { + .then(function (savedFoobar) { const foobarQuery = new Parse.Query('Foobar'); foobarQuery.include('barBaz'); foobarQuery.include('barBaz.bazoo'); foobarQuery.select(['fizz', 'barBaz.key', 'barBaz.bazoo.some']); - foobarQuery.get(savedFoobar.id).then(function(foobarObj) { + foobarQuery.get(savedFoobar.id).then(function (foobarObj) { equal(foobarObj.get('fizz'), 'buzz'); equal(foobarObj.get('foo'), undefined); if (foobarObj.has('barBaz')) { equal(foobarObj.get('barBaz').get('key'), 'value'); equal(foobarObj.get('barBaz').get('otherKey'), undefined); + equal(foobarObj.get('barBaz').get('bazoo').get('some'), 'thing'); equal( - foobarObj - .get('barBaz') - .get('bazoo') - .get('some'), - 'thing' - ); - equal( - foobarObj - .get('barBaz') - .get('bazoo') - .get('otherSome'), + foobarObj.get('barBaz').get('bazoo').get('otherSome'), undefined ); } else { @@ -4142,7 +4128,7 @@ describe('Parse.Query testing', () => { equal(result.child3.name, 'mo'); }); - it('includeAll', done => { + it('includeAll', (done) => { const child1 = new TestObject({ foo: 'bar', name: 'ac' }); const child2 = new TestObject({ foo: 'baz', name: 'flo' }); const child3 = new TestObject({ foo: 'bad', name: 'mo' }); @@ -4162,7 +4148,7 @@ describe('Parse.Query testing', () => { ) ); }) - .then(resp => { + .then((resp) => { const result = resp.data.results[0]; equal(result.child1.foo, 'bar'); equal(result.child2.foo, 'baz'); @@ -4174,7 +4160,7 @@ describe('Parse.Query testing', () => { }); }); - it('select nested keys 2 level includeAll', done => { + it('select nested keys 2 level includeAll', (done) => { const Foobar = new Parse.Object('Foobar'); const BarBaz = new Parse.Object('Barbaz'); const Bazoo = new Parse.Object('Bazoo'); @@ -4200,7 +4186,7 @@ describe('Parse.Query testing', () => { Foobar.set('group', Tang); return Foobar.save(); }) - .then(savedFoobar => { + .then((savedFoobar) => { const options = Object.assign( { url: Parse.serverURL + '/classes/Foobar', @@ -4216,7 +4202,7 @@ describe('Parse.Query testing', () => { ); return request(options); }) - .then(resp => { + .then((resp) => { const result = resp.data.results[0]; equal(result.group.clan, 'wu'); equal(result.foo, undefined); @@ -4230,7 +4216,7 @@ describe('Parse.Query testing', () => { .catch(done.fail); }); - it('select nested keys 2 level without include (issue #3185)', function(done) { + it('select nested keys 2 level without include (issue #3185)', function (done) { const Foobar = new Parse.Object('Foobar'); const BarBaz = new Parse.Object('Barbaz'); const Bazoo = new Parse.Object('Bazoo'); @@ -4250,30 +4236,21 @@ describe('Parse.Query testing', () => { Foobar.set('barBaz', BarBaz); return Foobar.save(); }) - .then(function(savedFoobar) { + .then(function (savedFoobar) { const foobarQuery = new Parse.Query('Foobar'); foobarQuery.select(['fizz', 'barBaz.key', 'barBaz.bazoo.some']); return foobarQuery.get(savedFoobar.id); }) - .then(foobarObj => { + .then((foobarObj) => { equal(foobarObj.get('fizz'), 'buzz'); equal(foobarObj.get('foo'), undefined); if (foobarObj.has('barBaz')) { equal(foobarObj.get('barBaz').get('key'), 'value'); equal(foobarObj.get('barBaz').get('otherKey'), undefined); if (foobarObj.get('barBaz').has('bazoo')) { + equal(foobarObj.get('barBaz').get('bazoo').get('some'), 'thing'); equal( - foobarObj - .get('barBaz') - .get('bazoo') - .get('some'), - 'thing' - ); - equal( - foobarObj - .get('barBaz') - .get('bazoo') - .get('otherSome'), + foobarObj.get('barBaz').get('bazoo').get('otherSome'), undefined ); } else { @@ -4286,7 +4263,7 @@ describe('Parse.Query testing', () => { }); }); - it('properly handles nested ors', function(done) { + it('properly handles nested ors', function (done) { const objects = []; while (objects.length != 4) { const obj = new Parse.Object('Object'); @@ -4304,18 +4281,18 @@ describe('Parse.Query testing', () => { const or01 = Parse.Query.or(q0, q1); return Parse.Query.or(or01, q2).find(); }) - .then(results => { + .then((results) => { expect(results.length).toBe(3); done(); }) - .catch(error => { + .catch((error) => { fail('should not fail'); jfail(error); done(); }); }); - it('should not depend on parameter order #3169', function(done) { + it('should not depend on parameter order #3169', function (done) { const score1 = new Parse.Object('Score', { scoreId: '1' }); const score2 = new Parse.Object('Score', { scoreId: '2' }); const game1 = new Parse.Object('Game', { gameId: '1' }); @@ -4346,16 +4323,16 @@ describe('Parse.Query testing', () => { }); }) .then( - response => { + (response) => { const results = response.data; expect(results.results.length).toBe(1); done(); }, - res => done.fail(res.data) + (res) => done.fail(res.data) ); }); - it('should not interfere with has when using select on field with undefined value #3999', done => { + it('should not interfere with has when using select on field with undefined value #3999', (done) => { const obj1 = new Parse.Object('TestObject'); const obj2 = new Parse.Object('OtherObject'); obj2.set('otherField', 1); @@ -4374,8 +4351,8 @@ describe('Parse.Query testing', () => { ]); return query.find(); }) - .then(results => { - results.forEach(result => { + .then((results) => { + results.forEach((result) => { equal(result.has('testPointerField'), result.get('shouldBe')); }); done(); @@ -4383,7 +4360,9 @@ describe('Parse.Query testing', () => { .catch(done.fail); }); - it_only_db('mongo')('should handle relative times correctly', function(done) { + it_only_db('mongo')('should handle relative times correctly', function ( + done + ) { const now = Date.now(); const obj1 = new Parse.Object('MyCustomObject', { name: 'obj1', @@ -4400,7 +4379,7 @@ describe('Parse.Query testing', () => { q.greaterThan('ttl', { $relativeTime: 'in 1 day' }); return q.find({ useMasterKey: true }); }) - .then(results => { + .then((results) => { expect(results.length).toBe(1); }) .then(() => { @@ -4408,7 +4387,7 @@ describe('Parse.Query testing', () => { q.greaterThan('ttl', { $relativeTime: '1 day ago' }); return q.find({ useMasterKey: true }); }) - .then(results => { + .then((results) => { expect(results.length).toBe(1); }) .then(() => { @@ -4416,7 +4395,7 @@ describe('Parse.Query testing', () => { q.lessThan('ttl', { $relativeTime: '5 days ago' }); return q.find({ useMasterKey: true }); }) - .then(results => { + .then((results) => { expect(results.length).toBe(0); }) .then(() => { @@ -4424,7 +4403,7 @@ describe('Parse.Query testing', () => { q.greaterThan('ttl', { $relativeTime: '3 days ago' }); return q.find({ useMasterKey: true }); }) - .then(results => { + .then((results) => { expect(results.length).toBe(2); }) .then(() => { @@ -4432,7 +4411,7 @@ describe('Parse.Query testing', () => { q.greaterThan('ttl', { $relativeTime: 'now' }); return q.find({ useMasterKey: true }); }) - .then(results => { + .then((results) => { expect(results.length).toBe(1); }) .then(() => { @@ -4441,7 +4420,7 @@ describe('Parse.Query testing', () => { q.lessThan('ttl', { $relativeTime: 'in 1 day' }); return q.find({ useMasterKey: true }); }) - .then(results => { + .then((results) => { expect(results.length).toBe(0); }) .then(() => { @@ -4449,13 +4428,13 @@ describe('Parse.Query testing', () => { q.greaterThan('ttl', { $relativeTime: '1 year 3 weeks ago' }); return q.find({ useMasterKey: true }); }) - .then(results => { + .then((results) => { expect(results.length).toBe(2); }) .then(done, done.fail); }); - it_only_db('mongo')('should error on invalid relative time', function(done) { + it_only_db('mongo')('should error on invalid relative time', function (done) { const obj1 = new Parse.Object('MyCustomObject', { name: 'obj1', ttl: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000), // 2 days from now @@ -4471,7 +4450,7 @@ describe('Parse.Query testing', () => { it_only_db('mongo')( 'should error when using $relativeTime on non-Date field', - function(done) { + function (done) { const obj1 = new Parse.Object('MyCustomObject', { name: 'obj1', nonDateField: 'abcd', @@ -4487,7 +4466,7 @@ describe('Parse.Query testing', () => { } ); - it('should match complex structure with dot notation when using matchesKeyInQuery', function(done) { + it('should match complex structure with dot notation when using matchesKeyInQuery', function (done) { const group1 = new Parse.Object('Group', { name: 'Group #1', }); @@ -4523,7 +4502,7 @@ describe('Parse.Query testing', () => { rolesOfTypeX ); - groupsWithRoleX.find().then(function(results) { + groupsWithRoleX.find().then(function (results) { equal(results.length, 1); equal(results[0].get('name'), group1.get('name')); done(); @@ -4531,7 +4510,7 @@ describe('Parse.Query testing', () => { }); }); - it('should match complex structure with dot notation when using doesNotMatchKeyInQuery', function(done) { + it('should match complex structure with dot notation when using doesNotMatchKeyInQuery', function (done) { const group1 = new Parse.Object('Group', { name: 'Group #1', }); @@ -4567,7 +4546,7 @@ describe('Parse.Query testing', () => { rolesOfTypeX ); - groupsWithRoleX.find().then(function(results) { + groupsWithRoleX.find().then(function (results) { equal(results.length, 1); equal(results[0].get('name'), group2.get('name')); done(); @@ -4640,7 +4619,7 @@ describe('Parse.Query testing', () => { equal(results[0].get('name'), group2.get('name')); }); - it('withJSON supports geoWithin.centerSphere', 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); @@ -4661,7 +4640,7 @@ describe('Parse.Query testing', () => { q.withJSON(jsonQ); return q.find(); }) - .then(results => { + .then((results) => { equal(results.length, 2); const q = new Parse.Query(TestObject); const jsonQ = q.toJSON(); @@ -4673,17 +4652,17 @@ describe('Parse.Query testing', () => { q.withJSON(jsonQ); return q.find(); }) - .then(results => { + .then((results) => { equal(results.length, 2); done(); }) - .catch(error => { + .catch((error) => { fail(error); done(); }); }); - it('withJSON with geoWithin.centerSphere fails without parameters', done => { + it('withJSON with geoWithin.centerSphere fails without parameters', (done) => { const q = new Parse.Query(TestObject); const jsonQ = q.toJSON(); jsonQ.where.location = { @@ -4694,11 +4673,11 @@ describe('Parse.Query testing', () => { q.withJSON(jsonQ); q.find() .then(done.fail) - .catch(e => expect(e.code).toBe(Parse.Error.INVALID_JSON)) + .catch((e) => expect(e.code).toBe(Parse.Error.INVALID_JSON)) .then(done); }); - it('withJSON with geoWithin.centerSphere fails with invalid distance', done => { + it('withJSON with geoWithin.centerSphere fails with invalid distance', (done) => { const q = new Parse.Query(TestObject); const jsonQ = q.toJSON(); jsonQ.where.location = { @@ -4709,11 +4688,11 @@ describe('Parse.Query testing', () => { q.withJSON(jsonQ); q.find() .then(done.fail) - .catch(e => expect(e.code).toBe(Parse.Error.INVALID_JSON)) + .catch((e) => expect(e.code).toBe(Parse.Error.INVALID_JSON)) .then(done); }); - it('withJSON with geoWithin.centerSphere fails with invalid coordinate', done => { + it('withJSON with geoWithin.centerSphere fails with invalid coordinate', (done) => { const q = new Parse.Query(TestObject); const jsonQ = q.toJSON(); jsonQ.where.location = { @@ -4727,7 +4706,7 @@ describe('Parse.Query testing', () => { .catch(() => done()); }); - it('withJSON with geoWithin.centerSphere fails with invalid geo point', done => { + it('withJSON with geoWithin.centerSphere fails with invalid geo point', (done) => { const q = new Parse.Query(TestObject); const jsonQ = q.toJSON(); jsonQ.where.location = { @@ -4869,7 +4848,7 @@ describe('Parse.Query testing', () => { equal(results[0].get('array').length, 105); }); - it('exclude keys (sdk query)', async done => { + it('exclude keys (sdk query)', async (done) => { const obj = new TestObject({ foo: 'baz', hello: 'world' }); await obj.save(); @@ -4882,7 +4861,7 @@ describe('Parse.Query testing', () => { done(); }); - xit('todo: exclude keys with select key (sdk query get)', async done => { + xit('todo: exclude keys with select key (sdk query get)', async (done) => { // there is some problem with js sdk caching const obj = new TestObject({ foo: 'baz', hello: 'world' }); @@ -4900,4 +4879,19 @@ describe('Parse.Query testing', () => { expect(object.get('hello')).toBeUndefined(); done(); }); + + it_only_db('mongo')('can use explain on User class', async () => { + // Create user + const user = new Parse.User(); + user.set('username', 'foo'); + user.set('password', 'bar'); + await user.save(); + // Query for user with explain + const query = new Parse.Query('_User'); + query.equalTo('objectId', user.id); + query.explain(); + const result = await query.find(); + // Validate + expect(result.executionStats).not.toBeUndefined(); + }); }); diff --git a/src/RestQuery.js b/src/RestQuery.js index 468446561c..79862d4aed 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -666,7 +666,7 @@ RestQuery.prototype.runFind = function(options = {}) { return this.config.database .find(this.className, this.restWhere, findOptions, this.auth) .then(results => { - if (this.className === '_User') { + if (this.className === '_User' && findOptions.explain !== true) { for (var result of results) { cleanResultAuthData(result); }