Fixed Cloud functions/triggers async rejection crashing server.
This commit is contained in:
@@ -4,10 +4,19 @@ Parse.Cloud.define('hello', function(req, res) {
|
|||||||
res.success('Hello world!');
|
res.success('Hello world!');
|
||||||
});
|
});
|
||||||
|
|
||||||
Parse.Cloud.beforeSave('BeforeSaveFailure', function(req, res) {
|
Parse.Cloud.beforeSave('BeforeSaveFail', function(req, res) {
|
||||||
res.error('You shall not pass!');
|
res.error('You shall not pass!');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Parse.Cloud.beforeSave('BeforeSaveFailWithPromise', function (req, res) {
|
||||||
|
var query = new Parse.Query('Yolo');
|
||||||
|
query.find().then(() => {
|
||||||
|
res.error('Nope');
|
||||||
|
}, () => {
|
||||||
|
res.success();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Parse.Cloud.beforeSave('BeforeSaveUnchanged', function(req, res) {
|
Parse.Cloud.beforeSave('BeforeSaveUnchanged', function(req, res) {
|
||||||
res.success();
|
res.success();
|
||||||
});
|
});
|
||||||
@@ -27,6 +36,15 @@ Parse.Cloud.beforeDelete('BeforeDeleteFail', function(req, res) {
|
|||||||
res.error('Nope');
|
res.error('Nope');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Parse.Cloud.beforeSave('BeforeDeleteFailWithPromise', function (req, res) {
|
||||||
|
var query = new Parse.Query('Yolo');
|
||||||
|
query.find().then(() => {
|
||||||
|
res.error('Nope');
|
||||||
|
}, () => {
|
||||||
|
res.success();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Parse.Cloud.beforeDelete('BeforeDeleteTest', function(req, res) {
|
Parse.Cloud.beforeDelete('BeforeDeleteTest', function(req, res) {
|
||||||
res.success();
|
res.success();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -153,12 +153,26 @@ describe('miscellaneous', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('basic beforeSave rejection', function(done) {
|
it('basic beforeSave rejection', function(done) {
|
||||||
var obj = new Parse.Object('BeforeSaveFailure');
|
var obj = new Parse.Object('BeforeSaveFail');
|
||||||
|
obj.set('foo', 'bar');
|
||||||
|
obj.save().then(() => {
|
||||||
|
fail('Should not have been able to save BeforeSaveFailure class.');
|
||||||
|
done();
|
||||||
|
}, () => {
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
it('basic beforeSave rejection via promise', function(done) {
|
||||||
|
var obj = new Parse.Object('BeforeSaveFailWithPromise');
|
||||||
obj.set('foo', 'bar');
|
obj.set('foo', 'bar');
|
||||||
obj.save().then(function() {
|
obj.save().then(function() {
|
||||||
fail('Should not have been able to save BeforeSaveFailure class.');
|
fail('Should not have been able to save BeforeSaveFailure class.');
|
||||||
done();
|
done();
|
||||||
}, function(error) {
|
}, function(error) {
|
||||||
|
expect(error.code).toEqual(Parse.Error.SCRIPT_FAILED);
|
||||||
|
expect(error.message).toEqual('Nope');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -250,6 +264,20 @@ describe('miscellaneous', function() {
|
|||||||
// We should have been able to fetch the object again
|
// We should have been able to fetch the object again
|
||||||
fail(error);
|
fail(error);
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
it('basic beforeDelete rejection via promise', function(done) {
|
||||||
|
var obj = new Parse.Object('BeforeDeleteFailWithPromise');
|
||||||
|
obj.set('foo', 'bar');
|
||||||
|
obj.save().then(function() {
|
||||||
|
fail('Should not have been able to save BeforeSaveFailure class.');
|
||||||
|
done();
|
||||||
|
}, function(error) {
|
||||||
|
expect(error.code).toEqual(Parse.Error.SCRIPT_FAILED);
|
||||||
|
expect(error.message).toEqual('Nope');
|
||||||
|
|
||||||
|
done();
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test beforeDelete success', function(done) {
|
it('test beforeDelete success', function(done) {
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ var getResponseObject = function(request, resolve, reject) {
|
|||||||
return resolve(response);
|
return resolve(response);
|
||||||
},
|
},
|
||||||
error: function(error) {
|
error: function(error) {
|
||||||
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, error);
|
var scriptError = new Parse.Error(Parse.Error.SCRIPT_FAILED, error);
|
||||||
|
return reject(scriptError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user