it('does not change inner object key names _rperm, _wperm', done => { new Parse.Object('O') .save({ innerObj: { _rperm: 7, _wperm: 8 } }) .then(object => new Parse.Query('O').get(object.id)) .then(object => { expect(object.get('innerObj')).toEqual({ _rperm: 7, _wperm: 8 }); done(); }); });
it('matches queries with doesNotExist constraint', function() { const obj = { id: new Id('Item', 'O1'), count: 15, }; let q = new Parse.Query('Item'); q.doesNotExist('name'); expect(matchesQuery(obj, q)).toBe(true); q = new Parse.Query('Item'); q.doesNotExist('count'); expect(matchesQuery(obj, q)).toBe(false); });
it_exclude_dbs(['postgres'])('match exists query', done => { const pipeline = [{ match: { score: { $exists: true } } }]; const query = new Parse.Query(TestObject); query.aggregate(pipeline).then(results => { expect(results.length).toEqual(4); 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 () { const query = new Parse.Query(TestObject); query.limit(1); query.find().then(function (results) { equal(results.length, 1); done(); }); }); });
// This test requires Date objects to be consistently stored as a Date. 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) { equal(results.length, 3); done(); }); }); });
it('should have access to context in beforeFind hook', async () => { Parse.Cloud.beforeFind('TestObject', (req) => { expect(req.context.a).toEqual('a'); }); const query = new Parse.Query('TestObject'); return query.find({ context: { a: 'a' } }); });
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)) .then(done); });
it('should get PII via API with Get using master key', done => { Parse.User.logOut().then(() => new Parse.Query(Parse.User) .get(user.id, { useMasterKey: true }) .then(fetchedUser => { expect(fetchedUser.get('email')).toBe(EMAIL); expect(fetchedUser.get('zip')).toBe(ZIP); expect(fetchedUser.get('ssn')).toBe(SSN); done(); }) ); });
it('matches blanket queries', function() { const obj = { id: new Id('Klass', 'O1'), value: 12, }; const q = new Parse.Query('Klass'); expect(matchesQuery(obj, q)).toBe(true); obj.id = new Id('Other', 'O1'); expect(matchesQuery(obj, q)).toBe(false); });
it('should get PII via API with Find using master key', done => { return Parse.User.logOut().then(() => new Parse.Query(Parse.User) .first({ useMasterKey: true }) .then(fetchedUser => { expect(fetchedUser.get('email')).toBe(EMAIL); expect(fetchedUser.get('zip')).toBe(ZIP); expect(fetchedUser.get('ssn')).toBe(SSN); done(); }) ); });
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) { equal(results.length, 1); equal(results[0].get('name'), 'item2'); 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)) .then(done); });
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) { equal(results.length, 2); done(); }); }); });
it('should not get PII via API with Get', done => { Parse.User.logOut().then(() => new Parse.Query(Parse.User).get(user.id).then(fetchedUser => { expect(fetchedUser.get('email')).toBe(undefined); expect(fetchedUser.get('zip')).toBe(undefined); expect(fetchedUser.get('ssn')).toBe(undefined); done(); }) ); });
it('does not change inner object key names _p_somethign', done => { new Parse.Object('O') .save({ innerObj: { _p_data: 7 } }) .then(object => new Parse.Query('O').get(object.id)) .then(object => { expect(object.get('innerObj')).toEqual({ _p_data: 7 }); done(); }); });