Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show a message if cloud functions are duplicated #6963

Merged
merged 4 commits into from
Oct 23, 2020
Merged
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
15 changes: 15 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ describe('Cloud Code', () => {
});
});

it('show warning on duplicate cloud functions', done => {
const logger = require('../lib/logger').logger;
spyOn(logger, 'warn').and.callFake(() => {});
Parse.Cloud.define('hello', () => {
return 'Hello world!';
});
Parse.Cloud.define('hello', () => {
return 'Hello world!';
});
expect(logger.warn).toHaveBeenCalledWith(
'Warning: Duplicate cloud functions exist for hello. Only the last one will be used and the others will be ignored.'
);
done();
});

it('is cleared cleared after the previous test', done => {
Parse.Cloud.run('hello', {}).catch(error => {
expect(error.code).toEqual(141);
Expand Down
5 changes: 5 additions & 0 deletions src/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ 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]) {
logger.warn(
`Warning: Duplicate cloud functions exist for ${lastComponent}. Only the last one will be used and the others will be ignored.`
);
}
store[lastComponent] = handler;
}

Expand Down