it('create a GameScore object', function(done) { const obj = new Parse.Object('GameScore'); obj.set('score', 1337); obj.save().then(function(obj) { expect(typeof obj.id).toBe('string'); expect(typeof obj.createdAt.toGMTString()).toBe('string'); done(); }, done.fail); });
new Parse.Query(Parse.Role) .containedIn( 'roles', ins.map(id => { const role = new Parse.Object(Parse.Role); role.id = id; return role; }) ) .each(result => results.push(result.toJSON()), { useMasterKey: true })
it('should be able to get own PII via API with object', done => { const userObj = new (Parse.Object.extend(Parse.User))(); userObj.id = user.id; return userObj .fetch() .then(fetchedUser => { expect(fetchedUser.get('email')).toBe(EMAIL); }) .then(done) .catch(done.fail); });
it('should have access to context as destroyAll argument', async () => { Parse.Cloud.beforeDelete('TestObject', (req) => { expect(req.context.a).toEqual('a'); }); Parse.Cloud.afterDelete('TestObject', (req) => { expect(req.context.a).toEqual('a'); }); const obj1 = new TestObject(); const obj2 = new TestObject(); await Parse.Object.saveAll([obj1, obj2]); await Parse.Object.destroyAll([obj1, obj2], { context: { a: 'a' } }); });
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 }); const q = new Parse.Query('MyCustomObject'); q.greaterThan('ttl', { $relativeTime: '-12 bananas ago' }); obj1 .save({ useMasterKey: true }) .then(() => q.find({ useMasterKey: true })) .then(done.fail, () => done()); });
it('should be able to get PII via API with object using master key', done => { return Parse.User.logOut().then(() => { const userObj = new (Parse.Object.extend(Parse.User))(); userObj.id = user.id; userObj .fetch({ useMasterKey: true }) .then(fetchedUser => expect(fetchedUser.get('email')).toBe(EMAIL)) .then(done) .catch(done.fail); }); });
/** * Verifies that an afterSave hook throwing an exception * will not prevent a successful save response from being returned */ it('should succeed on afterSave exception', done => { Parse.Cloud.afterSave('AfterSaveTestClass', function() { throw 'Exception'; }); const AfterSaveTestClass = Parse.Object.extend('AfterSaveTestClass'); const obj = new AfterSaveTestClass(); obj.save().then(done, done.fail); });
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(); }); }); });
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(); }); });
it('should not alter select', done => { const obj0 = new Parse.Object('MyObject') .set('white', true) .set('black', true); obj0.save().then(() => { new Parse.Query('MyObject').first().then(result => { expect(result.get('white')).toBe(true); expect(result.get('black')).toBe(true); done(); }); }); });
it('test beforeSave applies changes when beforeSave returns true', done => { Parse.Cloud.beforeSave('Insurance', function(req) { req.object.set('rate', '$49.99/Month'); return true; }); const insurance = new Parse.Object('Insurance'); insurance.set('rate', '$5.00/Month'); insurance.save().then(insurance => { expect(insurance.get('rate')).toEqual('$49.99/Month'); done(); }); });
it('case insensitive regex success', function (done) { const thing = new TestObject(); thing.set('myString', 'football'); Parse.Object.saveAll([thing]).then(function () { const query = new Parse.Query(TestObject); query.matches('myString', 'FootBall', 'i'); query.find().then(done); }); });
it('should not be able to get user PII via API with object', done => { const userObj = new (Parse.Object.extend(Parse.User))(); userObj.id = user.id; userObj .fetch() .then(fetchedUser => { expect(fetchedUser.get('email')).toBe(undefined); }) .then(done) .catch(done.fail); });
new Parse.Query(Parse.Role).containedIn('roles', ins.map(id => { const role = new Parse.Object(Parse.Role); role.id = id; return role; })).each(result => results.push(result.toJSON()), { useMasterKey: true })
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(); }); });