@@ -17,6 +17,7 @@ AV.Cloud.beforeSave("TestClass", function(request, response) {
1717 }
1818 assert . equal ( request . object . className , 'TestClass' ) ;
1919 request . object . set ( 'user' , request . user ) ;
20+ should . exist ( request . object . get ( '__before' ) ) ;
2021 response . success ( ) ;
2122} ) ;
2223
@@ -70,6 +71,7 @@ AV.Cloud.afterSave("TestError", function() {
7071AV . Cloud . afterUpdate ( "TestClass" , function ( request ) {
7172 var bizTime = new Date ( ) ;
7273 assert ( request . object . updatedKeys . indexOf ( 'foo' ) != - 1 ) ;
74+ should . exist ( request . object . get ( '__after' ) ) ;
7375 request . object . set ( 'bizTime' , bizTime ) ;
7476 request . object . save ( null , {
7577 success : function ( obj ) {
@@ -86,6 +88,15 @@ AV.Cloud.beforeDelete("TestClass", function(request, response) {
8688 response . success ( ) ;
8789} ) ;
8890
91+ AV . Cloud . beforeSave ( "HookMarkTest" , function ( request , response ) {
92+ should . exist ( request . object . get ( '__before' ) ) ;
93+ response . success ( request . object ) ;
94+ } ) ;
95+
96+ AV . Cloud . afterSave ( "HookMarkTest" , function ( request ) {
97+ should . exist ( request . object . get ( '__after' ) ) ;
98+ } ) ;
99+
89100AV . Cloud . onVerified ( 'sms' , function ( request ) {
90101 assert . equal ( request . object . id , '54fd6a03e4b06c41e00b1f40' ) ;
91102} ) ;
@@ -466,4 +477,71 @@ describe('hook', function() {
466477 } ) ;
467478 } ) ;
468479
480+ describe ( 'hookMark' , function ( ) {
481+ it ( 'before' , function ( done ) {
482+ request ( AV . Cloud )
483+ . post ( '/1/functions/HookMarkTest/beforeSave' )
484+ . set ( 'X-AVOSCloud-Application-Id' , appId )
485+ . set ( 'X-AVOSCloud-Application-Key' , appKey )
486+ . set ( 'Content-Type' , 'application/json' )
487+ . send ( {
488+ "object" : {
489+ "foo" : "bar" ,
490+ "__before" : 'abcdefg'
491+ }
492+ } )
493+ . expect ( 200 )
494+ . end ( function ( err , res ) {
495+ res . body . __before . should . equal ( 'abcdefg' ) ;
496+ done ( ) ;
497+ } ) ;
498+ } ) ;
499+
500+ it ( 'before_no_attrib' , function ( done ) {
501+ request ( AV . Cloud )
502+ . post ( '/1/functions/HookMarkTest/beforeSave' )
503+ . set ( 'X-AVOSCloud-Application-Id' , appId )
504+ . set ( 'X-AVOSCloud-Application-Key' , appKey )
505+ . set ( 'Content-Type' , 'application/json' )
506+ . send ( {
507+ "object" : {
508+ "foo" : "bar"
509+ }
510+ } )
511+ . expect ( 200 )
512+ . end ( function ( err , res ) {
513+ should . exist ( res . body . __before ) ;
514+ done ( ) ;
515+ } ) ;
516+ } ) ;
517+
518+ it ( 'after' , function ( done ) {
519+ request ( AV . Cloud )
520+ . post ( '/1/functions/HookMarkTest/afterSave' )
521+ . set ( 'X-AVOSCloud-Application-Id' , appId )
522+ . set ( 'X-AVOSCloud-Application-Key' , appKey )
523+ . set ( 'Content-Type' , 'application/json' )
524+ . send ( {
525+ "object" : {
526+ "foo" : "bar" ,
527+ "__after" : 'abcdefg'
528+ }
529+ } )
530+ . expect ( 200 , done ) ;
531+ } ) ;
532+
533+ it ( 'after_no_attrib' , function ( done ) {
534+ request ( AV . Cloud )
535+ . post ( '/1/functions/HookMarkTest/afterSave' )
536+ . set ( 'X-AVOSCloud-Application-Id' , appId )
537+ . set ( 'X-AVOSCloud-Application-Key' , appKey )
538+ . set ( 'Content-Type' , 'application/json' )
539+ . send ( {
540+ "object" : {
541+ "foo" : "bar"
542+ }
543+ } )
544+ . expect ( 200 , done ) ;
545+ } ) ;
546+ } ) ;
469547} ) ;
0 commit comments