Skip to content

Commit 85c44cd

Browse files
authored
Merge 1ddb981 into 65e5879
2 parents 65e5879 + 1ddb981 commit 85c44cd

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

spec/CloudCode.spec.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,16 @@ describe('Cloud Code', () => {
9292
});
9393
});
9494

95-
it('can get config', () => {
96-
const config = Parse.Server;
95+
it('can get and set config', () => {
9796
let currentConfig = Config.get('test');
98-
expect(Object.keys(config)).toEqual(Object.keys(currentConfig));
99-
config.silent = false;
100-
Parse.Server = config;
97+
expect(Object.keys(Parse.Server)).toEqual(Object.keys(currentConfig));
98+
Parse.Server.set('silent', ['abc']);
10199
currentConfig = Config.get('test');
102-
expect(currentConfig.silent).toBeFalse();
100+
expect(currentConfig.silent).toEqual(['abc']);
101+
});
102+
103+
it('can throw on invalid config', () => {
104+
expect(() => Parse.Server.set('foo', true)).toThrow('foo is not a valid Parse Server option');
103105
});
104106

105107
it('show warning on duplicate cloud functions', done => {

src/Config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,15 @@ export class Config {
694694
? this.pages.pagesEndpoint
695695
: 'apps';
696696
}
697+
698+
set(key, value) {
699+
if (!ParseServerOptions[key]) {
700+
throw `${key} is not a valid Parse Server option`;
701+
}
702+
this[key] = value;
703+
Config.put(this);
704+
return this;
705+
}
697706
}
698707

699708
export default Config;

src/ParseServer.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,16 +438,13 @@ class ParseServer {
438438

439439
function addParseCloud() {
440440
const ParseCloud = require('./cloud-code/Parse.Cloud');
441-
Object.defineProperty(Parse, 'Server', {
442-
get() {
443-
return Config.get(Parse.applicationId);
444-
},
445-
set(newVal) {
446-
newVal.appId = Parse.applicationId;
447-
Config.put(newVal);
448-
},
449-
configurable: true,
450-
});
441+
if (!Parse.Server) {
442+
Object.defineProperty(Parse, 'Server', {
443+
get() {
444+
return Config.get(Parse.applicationId);
445+
},
446+
});
447+
}
451448
Object.assign(Parse.Cloud, ParseCloud);
452449
global.Parse = Parse;
453450
}

0 commit comments

Comments
 (0)