@@ -1819,4 +1819,46 @@ describe('afterFind hooks', () => {
18191819 Parse . Cloud . afterSave ( '_PushStatus' , ( ) => { } ) ;
18201820 } ) . not . toThrow ( ) ;
18211821 } ) ;
1822+
1823+ it ( 'should skip afterFind hooks for aggregate' , ( done ) => {
1824+ const hook = {
1825+ method : function ( ) {
1826+ return Promise . reject ( ) ;
1827+ }
1828+ } ;
1829+ spyOn ( hook , 'method' ) . and . callThrough ( ) ;
1830+ Parse . Cloud . afterFind ( 'MyObject' , hook . method ) ;
1831+ const obj = new Parse . Object ( 'MyObject' )
1832+ const pipeline = [ {
1833+ group : { objectId : { } }
1834+ } ] ;
1835+ obj . save ( ) . then ( ( ) => {
1836+ const query = new Parse . Query ( 'MyObject' ) ;
1837+ return query . aggregate ( pipeline ) ;
1838+ } ) . then ( ( results ) => {
1839+ expect ( results [ 0 ] . objectId ) . toEqual ( null ) ;
1840+ expect ( hook . method ) . not . toHaveBeenCalled ( ) ;
1841+ done ( ) ;
1842+ } ) ;
1843+ } ) ;
1844+
1845+ it ( 'should skip afterFind hooks for distinct' , ( done ) => {
1846+ const hook = {
1847+ method : function ( ) {
1848+ return Promise . reject ( ) ;
1849+ }
1850+ } ;
1851+ spyOn ( hook , 'method' ) . and . callThrough ( ) ;
1852+ Parse . Cloud . afterFind ( 'MyObject' , hook . method ) ;
1853+ const obj = new Parse . Object ( 'MyObject' )
1854+ obj . set ( 'score' , 10 ) ;
1855+ obj . save ( ) . then ( ( ) => {
1856+ const query = new Parse . Query ( 'MyObject' ) ;
1857+ return query . distinct ( 'score' ) ;
1858+ } ) . then ( ( results ) => {
1859+ expect ( results [ 0 ] ) . toEqual ( 10 ) ;
1860+ expect ( hook . method ) . not . toHaveBeenCalled ( ) ;
1861+ done ( ) ;
1862+ } ) ;
1863+ } ) ;
18221864} ) ;
0 commit comments