Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ describe('Cloud Code', () => {
});
});

it('show warning on duplicate cloud functions', done => {
spyOn(console, 'log').and.callFake(() => {});
Parse.Cloud.define('hello', () => {
return 'Hello world!';
});
Parse.Cloud.define('hello', () => {
return 'Hello world!';
});
expect(console.log).toHaveBeenCalled();
done();
});

it('is cleared cleared after the previous test', done => {
Parse.Cloud.run('hello', {}).catch(error => {
expect(error.code).toEqual(141);
Expand Down
21 changes: 21 additions & 0 deletions src/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,27 @@ function getStore(category, name, applicationId) {
function add(category, name, handler, applicationId) {
const lastComponent = name.split('.').splice(-1);
const store = getStore(category, name, applicationId);
if (store[lastComponent]) {
const type = name.split('.')[0];
let warningMsg =
type == lastComponent ? `${lastComponent}` : `trigger ${type}`;
Comment thread
dblythy marked this conversation as resolved.
Outdated
const classSpecific = [
'beforeSave',
'afterSave',
'beforeDelete',
'afterDelete',
'beforeFind',
'afterFind',
'beforeSubscribe',
'afterEvent',
];
if (classSpecific.includes(type)) {
warningMsg += ` on class ${lastComponent}`;
Comment thread
dblythy marked this conversation as resolved.
Outdated
}
console.log(
Comment thread
dblythy marked this conversation as resolved.
Outdated
`Warning: Duplicate cloud functions exist for ${warningMsg}. The first will be ignored.`
Comment thread
dblythy marked this conversation as resolved.
Outdated
);
}
store[lastComponent] = handler;
}

Expand Down