@@ -2519,6 +2519,38 @@ describe('afterFind hooks', () => {
25192519 } ) ;
25202520 } ) ;
25212521
2522+ it ( 'should expose context in beforeSave/afterSave via header' , async ( ) => {
2523+ let calledBefore = false ;
2524+ let calledAfter = false ;
2525+ Parse . Cloud . beforeSave ( 'TestObject' , req => {
2526+ expect ( req . object . get ( 'foo' ) ) . toEqual ( 'bar' ) ;
2527+ expect ( req . context . otherKey ) . toBe ( 1 ) ;
2528+ expect ( req . context . key ) . toBe ( 'value' ) ;
2529+ calledBefore = true ;
2530+ } ) ;
2531+ Parse . Cloud . afterSave ( 'TestObject' , req => {
2532+ expect ( req . object . get ( 'foo' ) ) . toEqual ( 'bar' ) ;
2533+ expect ( req . context . otherKey ) . toBe ( 1 ) ;
2534+ expect ( req . context . key ) . toBe ( 'value' ) ;
2535+ calledAfter = true ;
2536+ } ) ;
2537+ const req = request ( {
2538+ method : 'POST' ,
2539+ url : 'http://localhost:8378/1/classes/TestObject' ,
2540+ headers : {
2541+ 'X-Parse-Application-Id' : 'test' ,
2542+ 'X-Parse-REST-API-Key' : 'rest' ,
2543+ 'X-Parse-Context' : '{"key":"value","otherKey":1}' ,
2544+ } ,
2545+ body : {
2546+ foo : 'bar' ,
2547+ } ,
2548+ } ) ;
2549+ const result = await req ;
2550+ expect ( calledBefore ) . toBe ( true ) ;
2551+ expect ( calledAfter ) . toBe ( true ) ;
2552+ } ) ;
2553+
25222554 it ( 'should expose context in before and afterSave' , async ( ) => {
25232555 let calledBefore = false ;
25242556 let calledAfter = false ;
0 commit comments