File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -967,6 +967,23 @@ describe('miscellaneous', function() {
967
967
} ) ;
968
968
} ) ;
969
969
970
+ it ( 'beforeSave change propagates through the save response' , ( done ) => {
971
+ Parse . Cloud . beforeSave ( 'ChangingObject' , function ( request , response ) {
972
+ request . object . set ( 'foo' , 'baz' ) ;
973
+ response . success ( ) ;
974
+ } ) ;
975
+ let obj = new Parse . Object ( 'ChangingObject' ) ;
976
+ obj . save ( { foo : 'bar' } ) . then ( ( objAgain ) => {
977
+ expect ( objAgain . get ( 'foo' ) ) . toEqual ( 'baz' ) ;
978
+ Parse . Cloud . _removeHook ( "Triggers" , "beforeSave" , "ChangingObject" ) ;
979
+ done ( ) ;
980
+ } , ( e ) => {
981
+ Parse . Cloud . _removeHook ( "Triggers" , "beforeSave" , "ChangingObject" ) ;
982
+ fail ( 'Should not have failed to save.' ) ;
983
+ done ( ) ;
984
+ } ) ;
985
+ } ) ;
986
+
970
987
it ( 'dedupes an installation properly and returns updatedAt' , ( done ) => {
971
988
let headers = {
972
989
'Content-Type' : 'application/json' ,
Original file line number Diff line number Diff line change @@ -164,6 +164,7 @@ RestWrite.prototype.runBeforeTrigger = function() {
164
164
} ) . then ( ( response ) => {
165
165
if ( response && response . object ) {
166
166
this . data = response . object ;
167
+ this . storage [ 'changedByTrigger' ] = true ;
167
168
// We should delete the objectId for an update write
168
169
if ( this . query && this . query . objectId ) {
169
170
delete this . data . objectId
@@ -806,6 +807,9 @@ RestWrite.prototype.runDatabaseOperation = function() {
806
807
objectId : this . data . objectId ,
807
808
createdAt : this . data . createdAt
808
809
} ;
810
+ if ( this . storage [ 'changedByTrigger' ] ) {
811
+ Object . assign ( resp , this . data ) ;
812
+ }
809
813
if ( this . storage [ 'token' ] ) {
810
814
resp . sessionToken = this . storage [ 'token' ] ;
811
815
}
You can’t perform that action at this time.
0 commit comments