@@ -15,6 +15,13 @@ describe('Cloud Code Logger', () => {
1515 // useful to flip to false for fine tuning :).
1616 silent : true ,
1717 logLevel : undefined ,
18+ logLevels : {
19+ cloudFunctionError : 'error' ,
20+ cloudFunctionSuccess : 'info' ,
21+ triggerAfter : 'info' ,
22+ triggerBeforeError : 'error' ,
23+ triggerBeforeSuccess : 'info' ,
24+ } ,
1825 } )
1926 . then ( ( ) => {
2027 return Parse . User . signUp ( 'tester' , 'abc' )
@@ -334,4 +341,53 @@ describe('Cloud Code Logger', () => {
334341 expect ( args [ 0 ] ) . toBe ( 'Parse error: ' ) ;
335342 expect ( args [ 1 ] . message ) . toBe ( 'Object not found.' ) ;
336343 } ) ;
344+
345+ it ( 'should log cloud function execution using the silent log level' , async ( ) => {
346+ await reconfigureServer ( {
347+ logLevels : {
348+ cloudFunctionSuccess : 'silent' ,
349+ cloudFunctionError : 'silent' ,
350+ } ,
351+ } ) ;
352+ Parse . Cloud . define ( 'aFunction' , ( ) => {
353+ return 'it worked!' ;
354+ } ) ;
355+ Parse . Cloud . define ( 'bFunction' , ( ) => {
356+ throw new Error ( 'Failed' ) ;
357+ } ) ;
358+ spy = spyOn ( Config . get ( 'test' ) . loggerController . adapter , 'log' ) . and . callThrough ( ) ;
359+
360+ await Parse . Cloud . run ( 'aFunction' , { foo : 'bar' } ) ;
361+ expect ( spy ) . toHaveBeenCalledTimes ( 0 ) ;
362+
363+ await expectAsync ( Parse . Cloud . run ( 'bFunction' , { foo : 'bar' } ) ) . toBeRejected ( ) ;
364+ // Not "Failed running cloud function message..."
365+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
366+ } ) ;
367+
368+ it ( 'should log cloud function triggers using the silent log level' , async ( ) => {
369+ await reconfigureServer ( {
370+ logLevels : {
371+ triggerAfter : 'silent' ,
372+ triggerBeforeSuccess : 'silent' ,
373+ triggerBeforeError : 'silent' ,
374+ } ,
375+ } ) ;
376+ Parse . Cloud . beforeSave ( 'TestClassError' , ( ) => {
377+ throw new Error ( 'Failed' ) ;
378+ } ) ;
379+ Parse . Cloud . beforeSave ( 'TestClass' , ( ) => { } ) ;
380+ Parse . Cloud . afterSave ( 'TestClass' , ( ) => { } ) ;
381+
382+ spy = spyOn ( Config . get ( 'test' ) . loggerController . adapter , 'log' ) . and . callThrough ( ) ;
383+
384+ const obj = new Parse . Object ( 'TestClass' ) ;
385+ await obj . save ( ) ;
386+ expect ( spy ) . toHaveBeenCalledTimes ( 0 ) ;
387+
388+ const objError = new Parse . Object ( 'TestClassError' ) ;
389+ await expectAsync ( objError . save ( ) ) . toBeRejected ( ) ;
390+ // Not "beforeSave failed for TestClassError for user ..."
391+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
392+ } ) ;
337393} ) ;
0 commit comments