File tree Expand file tree Collapse file tree 2 files changed +22
-12
lines changed Expand file tree Collapse file tree 2 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -92,14 +92,12 @@ 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 . setSilent ( [ 'abc' ] ) ;
101
99
currentConfig = Config . get ( 'test' ) ;
102
- expect ( currentConfig . silent ) . toBeFalse ( ) ;
100
+ expect ( currentConfig . silent ) . toEqual ( [ 'abc' ] ) ;
103
101
} ) ;
104
102
105
103
it ( 'show warning on duplicate cloud functions' , done => {
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ import { SecurityRouter } from './Routers/SecurityRouter';
45
45
import CheckRunner from './Security/CheckRunner' ;
46
46
import Deprecator from './Deprecator/Deprecator' ;
47
47
import { DefinedSchemas } from './SchemaMigrations/DefinedSchemas' ;
48
+ import { ParseServerOptions as ParseServerDefintions } from './Options/Definitions.js' ;
48
49
49
50
// Mutate the Parse object to add the Cloud Code handlers
50
51
addParseCloud ( ) ;
@@ -440,13 +441,24 @@ function addParseCloud() {
440
441
const ParseCloud = require ( './cloud-code/Parse.Cloud' ) ;
441
442
Object . defineProperty ( Parse , 'Server' , {
442
443
get ( ) {
443
- return Config . get ( Parse . applicationId ) ;
444
- } ,
445
- set ( newVal ) {
446
- newVal . appId = Parse . applicationId ;
447
- Config . put ( newVal ) ;
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` ;
451
+ }
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 ) ;
448
461
} ,
449
- configurable : true ,
450
462
} ) ;
451
463
Object . assign ( Parse . Cloud , ParseCloud ) ;
452
464
global . Parse = Parse ;
You can’t perform that action at this time.
0 commit comments