Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions spec/CloudCode.Validator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,27 @@ describe('cloud validator', () => {
});
});

it('does not leave an unhandled rejection when multiple fields fail validation (#8826)', async () => {
const rejections = [];
const onUnhandledRejection = reason => rejections.push(reason);
process.on('unhandledRejection', onUnhandledRejection);
try {
Parse.Cloud.define('hello', () => 'Hello world!', {
fields: {
type: { type: String, options: ['Option A', 'Option B'] },
project: { required: true },
},
});
await expectAsync(Parse.Cloud.run('hello', { type: 'Invalid' })).toBeRejectedWith(
jasmine.objectContaining({ code: Parse.Error.VALIDATION_ERROR })
);
await new Promise(resolve => setTimeout(resolve, 100));
expect(rejections).toEqual([]);
} finally {
process.removeListener('unhandledRejection', onUnhandledRejection);
}
});

it('set params options function', done => {
Parse.Cloud.define(
'hello',
Expand Down
6 changes: 3 additions & 3 deletions src/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ async function builtInTriggerValidator(options, request, auth) {
requiredParam(key);
}
} else {
const optionPromises = [];
const optionValidations = [];
for (const key in options.fields) {
const opt = options.fields[key];
let val = params[key];
Expand Down Expand Up @@ -850,12 +850,12 @@ async function builtInTriggerValidator(options, request, auth) {
}
}
if (opt.options) {
optionPromises.push(validateOptions(opt, key, val));
optionValidations.push([opt, key, val]);
}
}
}
}
await Promise.all(optionPromises);
await Promise.all(optionValidations.map(([o, k, v]) => validateOptions(o, k, v)));
}
let userRoles = options.requireAnyUserRoles;
let requireAllRoles = options.requireAllUserRoles;
Expand Down
Loading