@@ -520,6 +520,65 @@ describe('ParseServerRESTController', () => {
520520 ) ;
521521 } ) ;
522522
523+ it ( 'should strip undefined values from cloud function responses (with directAccess)' , async ( ) => {
524+ Parse . Cloud . define ( 'returnUndefinedValues' , ( ) => {
525+ return {
526+ definedKey : 'value' ,
527+ undefinedKey : undefined ,
528+ nested : { a : 1 , b : undefined } ,
529+ arrayWithUndefined : [ 1 , undefined , 3 ] ,
530+ } ;
531+ } ) ;
532+
533+ const res = await RESTController . request (
534+ 'POST' ,
535+ '/functions/returnUndefinedValues' ,
536+ { } ,
537+ { useMasterKey : true }
538+ ) ;
539+
540+ expect ( res . result . definedKey ) . toEqual ( 'value' ) ;
541+ expect ( res . result . undefinedKey ) . toBeUndefined ( ) ;
542+ expect ( Object . hasOwnProperty . call ( res . result , 'undefinedKey' ) ) . toBe ( false ) ;
543+ expect ( res . result . nested . a ) . toEqual ( 1 ) ;
544+ expect ( Object . hasOwnProperty . call ( res . result . nested , 'b' ) ) . toBe ( false ) ;
545+ expect ( res . result . arrayWithUndefined ) . toEqual ( [ 1 , null , 3 ] ) ;
546+ } ) ;
547+
548+ it ( 'should strip undefined values from cloud function responses (without directAccess)' , async ( ) => {
549+ Parse . Cloud . define ( 'returnUndefinedValuesHTTP' , ( ) => {
550+ return {
551+ definedKey : 'value' ,
552+ undefinedKey : undefined ,
553+ nested : { a : 1 , b : undefined } ,
554+ arrayWithUndefined : [ 1 , undefined , 3 ] ,
555+ } ;
556+ } ) ;
557+
558+ const serverURL = 'http://localhost:8378/1' ;
559+ const headers = {
560+ 'Content-Type' : 'application/json' ,
561+ 'X-Parse-Application-Id' : Parse . applicationId ,
562+ 'X-Parse-Master-Key' : Parse . masterKey ,
563+ } ;
564+
565+ const res = await request ( {
566+ method : 'POST' ,
567+ headers,
568+ url : `${ serverURL } /functions/returnUndefinedValuesHTTP` ,
569+ body : { } ,
570+ } ) ;
571+
572+ const result = res . data . result ;
573+
574+ expect ( result . definedKey ) . toEqual ( 'value' ) ;
575+ expect ( result . undefinedKey ) . toBeUndefined ( ) ;
576+ expect ( Object . hasOwnProperty . call ( result , 'undefinedKey' ) ) . toBe ( false ) ;
577+ expect ( result . nested . a ) . toEqual ( 1 ) ;
578+ expect ( Object . hasOwnProperty . call ( result . nested , 'b' ) ) . toBe ( false ) ;
579+ expect ( result . arrayWithUndefined ) . toEqual ( [ 1 , null , 3 ] ) ;
580+ } ) ;
581+
523582 it ( 'ensures sessionTokens are properly handled' , async ( ) => {
524583 const user = await Parse . User . signUp ( 'user' , 'pass' ) ;
525584 const sessionToken = user . getSessionToken ( ) ;
0 commit comments