Merge pull request #203 from ParsePlatform/nlutsenko.cloud.reject
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!');
|
||||
});
|
||||
|
||||
Parse.Cloud.beforeSave('BeforeSaveFailure', function(req, res) {
|
||||
Parse.Cloud.beforeSave('BeforeSaveFail', function(req, res) {
|
||||
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) {
|
||||
res.success();
|
||||
});
|
||||
@@ -27,6 +36,15 @@ Parse.Cloud.beforeDelete('BeforeDeleteFail', function(req, res) {
|
||||
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) {
|
||||
res.success();
|
||||
});
|
||||
|
||||
@@ -153,12 +153,26 @@ describe('miscellaneous', function() {
|
||||
});
|
||||
|
||||
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.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();
|
||||
})
|
||||
});
|
||||
@@ -250,6 +264,20 @@ describe('miscellaneous', function() {
|
||||
// We should have been able to fetch the object again
|
||||
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) {
|
||||
|
||||
@@ -57,7 +57,8 @@ var getResponseObject = function(request, resolve, reject) {
|
||||
return resolve(response);
|
||||
},
|
||||
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