Skip to content

Commit e1dacd5

Browse files
committed
add tests
1 parent 902666a commit e1dacd5

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

spec/CloudCode.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ describe('Cloud Code', () => {
100100
expect(currentConfig.silent).toEqual(['abc']);
101101
});
102102

103+
it('can set config with two args', () => {
104+
Parse.Server.set('silent', ['abc']);
105+
const currentConfig = Config.get('test');
106+
expect(currentConfig.silent).toEqual(['abc']);
107+
});
108+
109+
it('can throw on invalid config', () => {
110+
expect(() => Parse.Server.setFoo()).toThrow('foo is not a valid Parse Server option');
111+
});
112+
103113
it('show warning on duplicate cloud functions', done => {
104114
const logger = require('../lib/logger').logger;
105115
spyOn(logger, 'warn').and.callFake(() => {});

src/ParseServer.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -439,27 +439,38 @@ class ParseServer {
439439

440440
function addParseCloud() {
441441
const ParseCloud = require('./cloud-code/Parse.Cloud');
442-
Object.defineProperty(Parse, 'Server', {
443-
get() {
444-
const target = Config.get(Parse.applicationId);
445-
const handler2 = {
446-
get(obj, prop) {
447-
if (prop.substring(0, 3) === 'set') {
448-
const method = `${prop.charAt(3).toLowerCase()}${prop.substring(4, prop.length)}`;
449-
if (!ParseServerDefintions[method]) {
450-
throw `${method} is not a valid Parse Server option`;
442+
if (!Parse.Server) {
443+
Object.defineProperty(Parse, 'Server', {
444+
get() {
445+
const target = Config.get(Parse.applicationId);
446+
const handler2 = {
447+
get(obj, prop) {
448+
if (prop.substring(0, 3) === 'set') {
449+
const validMethod = method => {
450+
if (!ParseServerDefintions[method]) {
451+
throw `${method} is not a valid Parse Server option`;
452+
}
453+
};
454+
const assignValue = (key, value) => {
455+
validMethod(key);
456+
obj[key] = value;
457+
Config.put(obj);
458+
};
459+
if (prop.length === 3) {
460+
return assignValue;
461+
}
462+
const method = `${prop.charAt(3).toLowerCase()}${prop.substring(4, prop.length)}`;
463+
return value => {
464+
return assignValue(method, value);
465+
};
451466
}
452-
return value => {
453-
obj[method] = value;
454-
Config.put(obj);
455-
};
456-
}
457-
return obj[prop];
458-
},
459-
};
460-
return new Proxy(target, handler2);
461-
},
462-
});
467+
return obj[prop];
468+
},
469+
};
470+
return new Proxy(target, handler2);
471+
},
472+
});
473+
}
463474
Object.assign(Parse.Cloud, ParseCloud);
464475
global.Parse = Parse;
465476
}

0 commit comments

Comments
 (0)