@@ -201,6 +201,61 @@ describe('Cloud Code', () => {
201201 }
202202 } ) ;
203203
204+ it ( 'beforeFind can short circuit' , async ( ) => {
205+ Parse . Cloud . beforeFind ( 'beforeFind' , ( ) => {
206+ return new Parse . Object ( 'TestObject' , { foo : 'bar' } ) ;
207+ } ) ;
208+ Parse . Cloud . afterFind ( 'beforeFind' , ( ) => {
209+ throw 'afterFind should not run' ;
210+ } ) ;
211+ const obj = new Parse . Object ( 'beforeFind' ) ;
212+ await obj . save ( ) ;
213+ const newObj = await new Parse . Query ( 'beforeFind' ) . first ( ) ;
214+ expect ( newObj . className ) . toBe ( 'TestObject' ) ;
215+ expect ( newObj . toJSON ( ) ) . toEqual ( { foo : 'bar' } ) ;
216+ } ) ;
217+
218+ it ( 'beforeFind can short circuit arrays' , async ( ) => {
219+ Parse . Cloud . beforeFind ( 'beforeFind' , ( ) => {
220+ return [ new Parse . Object ( 'TestObject' , { foo : 'bar' } ) ] ;
221+ } ) ;
222+ Parse . Cloud . afterFind ( 'beforeFind' , ( ) => {
223+ throw 'afterFind should not run' ;
224+ } ) ;
225+ const obj = new Parse . Object ( 'beforeFind' ) ;
226+ await obj . save ( ) ;
227+ const newObj = await new Parse . Query ( 'beforeFind' ) . first ( ) ;
228+ expect ( newObj . className ) . toBe ( 'TestObject' ) ;
229+ expect ( newObj . toJSON ( ) ) . toEqual ( { foo : 'bar' } ) ;
230+ } ) ;
231+
232+ it ( 'beforeFind can short circuit get' , async ( ) => {
233+ Parse . Cloud . beforeFind ( 'beforeFind' , ( ) => {
234+ return [ new Parse . Object ( 'TestObject' , { foo : 'bar' } ) ] ;
235+ } ) ;
236+ Parse . Cloud . afterFind ( 'beforeFind' , ( ) => {
237+ throw 'afterFind should not run' ;
238+ } ) ;
239+ const obj = new Parse . Object ( 'beforeFind' ) ;
240+ await obj . save ( ) ;
241+ const newObj = await new Parse . Query ( 'beforeFind' ) . get ( obj . id ) ;
242+ expect ( newObj . className ) . toBe ( 'TestObject' ) ;
243+ expect ( newObj . toJSON ( ) ) . toEqual ( { foo : 'bar' } ) ;
244+ } ) ;
245+
246+ it ( 'beforeFind can short circuit empty array' , async ( ) => {
247+ Parse . Cloud . beforeFind ( 'beforeFind' , ( ) => {
248+ return [ ] ;
249+ } ) ;
250+ Parse . Cloud . afterFind ( 'beforeFind' , ( ) => {
251+ throw 'afterFind should not run' ;
252+ } ) ;
253+ const obj = new Parse . Object ( 'beforeFind' ) ;
254+ await obj . save ( ) ;
255+ const newObj = await new Parse . Query ( 'beforeFind' ) . first ( ) ;
256+ expect ( newObj ) . toBeUndefined ( ) ;
257+ } ) ;
258+
204259 it ( 'beforeSave rejection with custom error code' , function ( done ) {
205260 Parse . Cloud . beforeSave ( 'BeforeSaveFailWithErrorCode' , function ( ) {
206261 throw new Parse . Error ( 999 , 'Nope' ) ;
0 commit comments