File tree Expand file tree Collapse file tree 3 files changed +24
-16
lines changed Expand file tree Collapse file tree 3 files changed +24
-16
lines changed Original file line number Diff line number Diff 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 => {
Original file line number Diff line number Diff 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
699708export default Config ;
Original file line number Diff line number Diff line change @@ -438,16 +438,13 @@ class ParseServer {
438438
439439function 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}
You can’t perform that action at this time.
0 commit comments