@@ -801,4 +801,37 @@ describe('Parse.Relation testing', () => {
801
801
done ( ) ;
802
802
} ) ;
803
803
} ) ;
804
+
805
+ it ( 'ensures beforeFind on relation doesnt side effect' , ( done ) => {
806
+ const parent = new Parse . Object ( 'Parent' ) ;
807
+ const child = new Parse . Object ( 'Child' ) ;
808
+ child . save ( ) . then ( ( ) => {
809
+ parent . relation ( 'children' ) . add ( child ) ;
810
+ return parent . save ( ) ;
811
+ } ) . then ( ( ) => {
812
+ // We need to use a new reference otherwise the JS SDK remembers the className for a relation
813
+ // After saves or finds
814
+ const otherParent = new Parse . Object ( 'Parent' ) ;
815
+ otherParent . id = parent . id ;
816
+ return otherParent . relation ( 'children' ) . query ( ) . find ( ) ;
817
+ } ) . then ( ( children ) => {
818
+ // Without an after find all is good, all results have been redirected with proper className
819
+ children . forEach ( ( child ) => expect ( child . className ) . toBe ( 'Child' ) ) ;
820
+ // Setup the afterFind
821
+ Parse . Cloud . afterFind ( 'Child' , ( req ) => {
822
+ return Promise . resolve ( req . objects . map ( ( child ) => {
823
+ child . set ( 'afterFound' , true ) ;
824
+ return child ;
825
+ } ) ) ;
826
+ } ) ;
827
+ const otherParent = new Parse . Object ( 'Parent' ) ;
828
+ otherParent . id = parent . id ;
829
+ return otherParent . relation ( 'children' ) . query ( ) . find ( ) ;
830
+ } ) . then ( ( children ) => {
831
+ children . forEach ( ( child ) => {
832
+ expect ( child . className ) . toBe ( 'Child' ) ;
833
+ expect ( child . get ( 'afterFound' ) ) . toBe ( true ) ;
834
+ } ) ;
835
+ } ) . then ( done ) . catch ( done . fail ) ;
836
+ } ) ;
804
837
} ) ;
0 commit comments