diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index c02999ad51..2dca57da08 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -92,14 +92,16 @@ describe('Cloud Code', () => { }); }); - it('can get config', () => { - const config = Parse.Server; + it('can get and set config', () => { let currentConfig = Config.get('test'); - expect(Object.keys(config)).toEqual(Object.keys(currentConfig)); - config.silent = false; - Parse.Server = config; + expect(Object.keys(Parse.Server)).toEqual(Object.keys(currentConfig)); + Parse.Server.set('silent', ['abc']); currentConfig = Config.get('test'); - expect(currentConfig.silent).toBeFalse(); + expect(currentConfig.silent).toEqual(['abc']); + }); + + it('can throw on invalid config', () => { + expect(() => Parse.Server.set('foo', true)).toThrow('foo is not a valid Parse Server option'); }); it('show warning on duplicate cloud functions', done => { diff --git a/src/Config.js b/src/Config.js index 812d28c367..7c0b035be2 100644 --- a/src/Config.js +++ b/src/Config.js @@ -694,6 +694,15 @@ export class Config { ? this.pages.pagesEndpoint : 'apps'; } + + set(key, value) { + if (!ParseServerOptions[key]) { + throw `${key} is not a valid Parse Server option`; + } + this[key] = value; + Config.put(this); + return this; + } } export default Config; diff --git a/src/ParseServer.js b/src/ParseServer.js index 04379ecfd3..36a1a606d8 100644 --- a/src/ParseServer.js +++ b/src/ParseServer.js @@ -438,16 +438,13 @@ class ParseServer { function addParseCloud() { const ParseCloud = require('./cloud-code/Parse.Cloud'); - Object.defineProperty(Parse, 'Server', { - get() { - return Config.get(Parse.applicationId); - }, - set(newVal) { - newVal.appId = Parse.applicationId; - Config.put(newVal); - }, - configurable: true, - }); + if (!Parse.Server) { + Object.defineProperty(Parse, 'Server', { + get() { + return Config.get(Parse.applicationId); + }, + }); + } Object.assign(Parse.Cloud, ParseCloud); global.Parse = Parse; }