File tree 3 files changed +24
-16
lines changed 3 files changed +24
-16
lines changed Original file line number Diff line number Diff line change @@ -92,14 +92,16 @@ describe('Cloud Code', () => {
92
92
} ) ;
93
93
} ) ;
94
94
95
- it ( 'can get config' , ( ) => {
96
- const config = Parse . Server ;
95
+ it ( 'can get and set config' , ( ) => {
97
96
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' ] ) ;
101
99
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' ) ;
103
105
} ) ;
104
106
105
107
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 {
694
694
? this . pages . pagesEndpoint
695
695
: 'apps' ;
696
696
}
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
+ }
697
706
}
698
707
699
708
export default Config ;
Original file line number Diff line number Diff line change @@ -438,16 +438,13 @@ class ParseServer {
438
438
439
439
function addParseCloud ( ) {
440
440
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
+ }
451
448
Object . assign ( Parse . Cloud , ParseCloud ) ;
452
449
global . Parse = Parse ;
453
450
}
You can’t perform that action at this time.
0 commit comments