diff --git a/integration/test/ParseACLTest.js b/integration/test/ParseACLTest.js index 4251f059c..d1340cfe7 100644 --- a/integration/test/ParseACLTest.js +++ b/integration/test/ParseACLTest.js @@ -27,6 +27,20 @@ describe('Parse.ACL', () => { assert(o); }); + it('can set ACL from json', async () => { + Parse.User.enableUnsafeCurrentUser(); + const user = new Parse.User(); + const object = new TestObject(); + user.set('username', 'torn'); + user.set('password', 'acl'); + await user.signUp(); + const acl = new Parse.ACL(user); + object.setACL(acl); + const json = object.toJSON(); + await object.save(json); + assert.equal(acl.equals(object.getACL()), true); + }); + it('disables public get access', async () => { const user = new Parse.User(); const object = new TestObject(); diff --git a/integration/test/ParseEventuallyQueueTest.js b/integration/test/ParseEventuallyQueueTest.js index 6ce6358cb..1d8157553 100644 --- a/integration/test/ParseEventuallyQueueTest.js +++ b/integration/test/ParseEventuallyQueueTest.js @@ -220,6 +220,49 @@ describe('Parse EventuallyQueue', () => { assert.strictEqual(results.length, 1); }); + it('can saveEventually on object with ACL', async () => { + Parse.User.enableUnsafeCurrentUser(); + const parseServer = await reconfigureServer(); + const user = new Parse.User(); + user.set('username', 'torn'); + user.set('password', 'acl'); + await user.signUp(); + + const acl = new Parse.ACL(user); + const object = new TestObject({ hash: 'saveSecret' }); + object.setACL(acl); + + await new Promise((resolve) => parseServer.server.close(resolve)); + + await object.saveEventually(); + + let length = await Parse.EventuallyQueue.length(); + assert(Parse.EventuallyQueue.isPolling()); + assert.strictEqual(length, 1); + + await reconfigureServer({}); + + while (Parse.EventuallyQueue.isPolling()) { + await sleep(100); + } + assert.strictEqual(Parse.EventuallyQueue.isPolling(), false); + + length = await Parse.EventuallyQueue.length(); + while (length) { + await sleep(100); + } + length = await Parse.EventuallyQueue.length(); + assert.strictEqual(length, 0); + + const query = new Parse.Query('TestObject'); + query.equalTo('hash', 'saveSecret'); + let results = await query.find(); + while (results.length === 0) { + results = await query.find(); + } + assert.strictEqual(results.length, 1); + }); + it('can destroyEventually', async () => { const parseServer = await reconfigureServer(); const object = new TestObject({ hash: 'deleteSecret' }); diff --git a/src/ParseObject.js b/src/ParseObject.js index 32701191b..eafa7f45d 100644 --- a/src/ParseObject.js +++ b/src/ParseObject.js @@ -1308,15 +1308,17 @@ class ParseObject { options = arg3; } + options = options || {}; if (attrs) { - const validation = this.validate(attrs); - if (validation) { - return Promise.reject(validation); + let validationError; + options.error = (_, validation) => { + validationError = validation; + }; + const success = this.set(attrs, options); + if (!success) { + return Promise.reject(validationError); } - this.set(attrs, options); } - - options = options || {}; const saveOptions = {}; if (options.hasOwnProperty('useMasterKey')) { saveOptions.useMasterKey = !!options.useMasterKey; diff --git a/src/__tests__/ParseObject-test.js b/src/__tests__/ParseObject-test.js index c67c4a3e1..2066a8979 100644 --- a/src/__tests__/ParseObject-test.js +++ b/src/__tests__/ParseObject-test.js @@ -364,6 +364,13 @@ describe('ParseObject', () => { expect(o.getACL()).toEqual(ACL); }); + it('encodes ACL from json', () => { + const ACL = new ParseACL({ user1: { read: true } }); + const o = new ParseObject('Item'); + o.set({ ACL: ACL.toJSON() }); + expect(o.getACL()).toEqual(ACL); + }); + it('can be rendered to JSON', () => { let o = new ParseObject('Item'); o.set({