@@ -3635,7 +3635,7 @@ describe('afterLogin hook', () => {
3635
3635
} ) ;
3636
3636
3637
3637
describe ( 'saveFile hooks' , ( ) => {
3638
- it ( 'beforeSaveFile should return file that is already saved and not save anything to files adapter' , async ( ) => {
3638
+ it ( 'beforeSave(Parse.File) should return file that is already saved and not save anything to files adapter' , async ( ) => {
3639
3639
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3640
3640
const createFileSpy = spyOn ( mockAdapter , 'createFile' ) . and . callThrough ( ) ;
3641
3641
Parse . Cloud . beforeSave ( Parse . File , ( ) => {
@@ -3651,7 +3651,7 @@ describe('saveFile hooks', () => {
3651
3651
expect ( createFileSpy ) . not . toHaveBeenCalled ( ) ;
3652
3652
} ) ;
3653
3653
3654
- it ( 'beforeSaveFile should throw error' , async ( ) => {
3654
+ it ( 'beforeSave(Parse.File) should throw error' , async ( ) => {
3655
3655
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3656
3656
Parse . Cloud . beforeSave ( Parse . File , ( ) => {
3657
3657
throw new Parse . Error ( 400 , 'some-error-message' ) ;
@@ -3664,7 +3664,7 @@ describe('saveFile hooks', () => {
3664
3664
}
3665
3665
} ) ;
3666
3666
3667
- it ( 'beforeSaveFile should change values of uploaded file by editing fileObject directly' , async ( ) => {
3667
+ it ( 'beforeSave(Parse.File) should change values of uploaded file by editing fileObject directly' , async ( ) => {
3668
3668
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3669
3669
const createFileSpy = spyOn ( mockAdapter , 'createFile' ) . and . callThrough ( ) ;
3670
3670
Parse . Cloud . beforeSave ( Parse . File , async req => {
@@ -3693,7 +3693,7 @@ describe('saveFile hooks', () => {
3693
3693
) ;
3694
3694
} ) ;
3695
3695
3696
- it ( 'beforeSaveFile should change values by returning new fileObject' , async ( ) => {
3696
+ it ( 'beforeSave(Parse.File) should change values by returning new fileObject' , async ( ) => {
3697
3697
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3698
3698
const createFileSpy = spyOn ( mockAdapter , 'createFile' ) . and . callThrough ( ) ;
3699
3699
Parse . Cloud . beforeSave ( Parse . File , async req => {
@@ -3727,7 +3727,7 @@ describe('saveFile hooks', () => {
3727
3727
expect ( file . _name . indexOf ( expectedFileName ) ) . toBe ( file . _name . length - expectedFileName . length ) ;
3728
3728
} ) ;
3729
3729
3730
- it ( 'beforeSaveFile should contain metadata and tags saved from client' , async ( ) => {
3730
+ it ( 'beforeSave(Parse.File) should contain metadata and tags saved from client' , async ( ) => {
3731
3731
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3732
3732
const createFileSpy = spyOn ( mockAdapter , 'createFile' ) . and . callThrough ( ) ;
3733
3733
Parse . Cloud . beforeSave ( Parse . File , async req => {
@@ -3755,7 +3755,7 @@ describe('saveFile hooks', () => {
3755
3755
) ;
3756
3756
} ) ;
3757
3757
3758
- it ( 'beforeSaveFile should return same file data with new file name' , async ( ) => {
3758
+ it ( 'beforeSave(Parse.File) should return same file data with new file name' , async ( ) => {
3759
3759
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3760
3760
const config = Config . get ( 'test' ) ;
3761
3761
config . filesController . options . preserveFileName = true ;
@@ -3770,7 +3770,7 @@ describe('saveFile hooks', () => {
3770
3770
expect ( result . name ( ) ) . toBe ( '2020-04-01.txt' ) ;
3771
3771
} ) ;
3772
3772
3773
- it ( 'afterSaveFile should set fileSize to null if beforeSave returns an already saved file' , async ( ) => {
3773
+ it ( 'afterSave(Parse.File) should set fileSize to null if beforeSave returns an already saved file' , async ( ) => {
3774
3774
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3775
3775
const createFileSpy = spyOn ( mockAdapter , 'createFile' ) . and . callThrough ( ) ;
3776
3776
Parse . Cloud . beforeSave ( Parse . File , req => {
@@ -3790,7 +3790,7 @@ describe('saveFile hooks', () => {
3790
3790
expect ( createFileSpy ) . not . toHaveBeenCalled ( ) ;
3791
3791
} ) ;
3792
3792
3793
- it ( 'afterSaveFile should throw error' , async ( ) => {
3793
+ it ( 'afterSave(Parse.File) should throw error' , async ( ) => {
3794
3794
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3795
3795
Parse . Cloud . afterSave ( Parse . File , async ( ) => {
3796
3796
throw new Parse . Error ( 400 , 'some-error-message' ) ;
@@ -3804,7 +3804,7 @@ describe('saveFile hooks', () => {
3804
3804
}
3805
3805
} ) ;
3806
3806
3807
- it ( 'afterSaveFile should call with fileObject' , async done => {
3807
+ it ( 'afterSave(Parse.File) should call with fileObject' , async done => {
3808
3808
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3809
3809
Parse . Cloud . beforeSave ( Parse . File , async req => {
3810
3810
req . file . setTags ( { tagA : 'some-tag' } ) ;
@@ -3820,7 +3820,7 @@ describe('saveFile hooks', () => {
3820
3820
await file . save ( { useMasterKey : true } ) ;
3821
3821
} ) ;
3822
3822
3823
- it ( 'afterSaveFile should change fileSize when file data changes' , async done => {
3823
+ it ( 'afterSave(Parse.File) should change fileSize when file data changes' , async done => {
3824
3824
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3825
3825
Parse . Cloud . beforeSave ( Parse . File , async req => {
3826
3826
expect ( req . fileSize ) . toBe ( 3 ) ;
@@ -3837,7 +3837,7 @@ describe('saveFile hooks', () => {
3837
3837
await file . save ( { useMasterKey : true } ) ;
3838
3838
} ) ;
3839
3839
3840
- it ( 'beforeDeleteFile should call with fileObject' , async ( ) => {
3840
+ it ( 'beforeDelete(Parse.File) should call with fileObject' , async ( ) => {
3841
3841
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3842
3842
Parse . Cloud . beforeDelete ( Parse . File , req => {
3843
3843
expect ( req . file ) . toBeInstanceOf ( Parse . File ) ;
@@ -3849,7 +3849,7 @@ describe('saveFile hooks', () => {
3849
3849
await file . destroy ( { useMasterKey : true } ) ;
3850
3850
} ) ;
3851
3851
3852
- it ( 'beforeDeleteFile should throw error' , async done => {
3852
+ it ( 'beforeDelete(Parse.File) should throw error' , async done => {
3853
3853
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3854
3854
Parse . Cloud . beforeDelete ( Parse . File , ( ) => {
3855
3855
throw new Error ( 'some error message' ) ;
@@ -3863,7 +3863,7 @@ describe('saveFile hooks', () => {
3863
3863
}
3864
3864
} ) ;
3865
3865
3866
- it ( 'afterDeleteFile should call with fileObject' , async done => {
3866
+ it ( 'afterDelete(Parse.File) should call with fileObject' , async done => {
3867
3867
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3868
3868
Parse . Cloud . beforeDelete ( Parse . File , req => {
3869
3869
expect ( req . file ) . toBeInstanceOf ( Parse . File ) ;
@@ -3880,7 +3880,7 @@ describe('saveFile hooks', () => {
3880
3880
await file . destroy ( { useMasterKey : true } ) ;
3881
3881
} ) ;
3882
3882
3883
- it ( 'beforeSaveFile should not change file if nothing is returned' , async ( ) => {
3883
+ it ( 'beforeSave(Parse.File) should not change file if nothing is returned' , async ( ) => {
3884
3884
await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3885
3885
Parse . Cloud . beforeSave ( Parse . File , ( ) => {
3886
3886
return ;
@@ -3890,7 +3890,7 @@ describe('saveFile hooks', () => {
3890
3890
expect ( result ) . toBe ( file ) ;
3891
3891
} ) ;
3892
3892
3893
- it ( 'throw custom error from beforeSaveFile ' , async done => {
3893
+ it ( 'throw custom error from beforeSave(Parse.File) ' , async done => {
3894
3894
Parse . Cloud . beforeSave ( Parse . File , ( ) => {
3895
3895
throw new Parse . Error ( Parse . Error . SCRIPT_FAILED , 'It should fail' ) ;
3896
3896
} ) ;
@@ -3904,7 +3904,7 @@ describe('saveFile hooks', () => {
3904
3904
}
3905
3905
} ) ;
3906
3906
3907
- it ( 'throw empty error from beforeSaveFile ' , async done => {
3907
+ it ( 'throw empty error from beforeSave(Parse.File) ' , async done => {
3908
3908
Parse . Cloud . beforeSave ( Parse . File , ( ) => {
3909
3909
throw null ;
3910
3910
} ) ;
@@ -3917,55 +3917,6 @@ describe('saveFile hooks', () => {
3917
3917
done ( ) ;
3918
3918
}
3919
3919
} ) ;
3920
-
3921
- it ( 'legacy hooks' , async ( ) => {
3922
- await reconfigureServer ( { filesAdapter : mockAdapter } ) ;
3923
- const logger = require ( '../lib/logger' ) . logger ;
3924
- const logSpy = spyOn ( logger , 'warn' ) . and . callFake ( ( ) => { } ) ;
3925
- const triggers = {
3926
- beforeSaveFile ( req ) {
3927
- req . file . setTags ( { tagA : 'some-tag' } ) ;
3928
- req . file . setMetadata ( { foo : 'bar' } ) ;
3929
- expect ( req . triggerName ) . toEqual ( 'beforeSave' ) ;
3930
- expect ( req . master ) . toBe ( true ) ;
3931
- } ,
3932
- afterSaveFile ( req ) {
3933
- expect ( req . master ) . toBe ( true ) ;
3934
- expect ( req . file . _tags ) . toEqual ( { tagA : 'some-tag' } ) ;
3935
- expect ( req . file . _metadata ) . toEqual ( { foo : 'bar' } ) ;
3936
- } ,
3937
- beforeDeleteFile ( req ) {
3938
- expect ( req . file ) . toBeInstanceOf ( Parse . File ) ;
3939
- expect ( req . file . _name ) . toEqual ( 'popeye.txt' ) ;
3940
- expect ( req . file . _url ) . toEqual ( 'http://www.somewhere.com/popeye.txt' ) ;
3941
- expect ( req . fileSize ) . toBe ( null ) ;
3942
- } ,
3943
- afterDeleteFile ( req ) {
3944
- expect ( req . file ) . toBeInstanceOf ( Parse . File ) ;
3945
- expect ( req . file . _name ) . toEqual ( 'popeye.txt' ) ;
3946
- expect ( req . file . _url ) . toEqual ( 'http://www.somewhere.com/popeye.txt' ) ;
3947
- } ,
3948
- } ;
3949
-
3950
- for ( const key in triggers ) {
3951
- spyOn ( triggers , key ) . and . callThrough ( ) ;
3952
- Parse . Cloud [ key ] ( triggers [ key ] ) ;
3953
- }
3954
-
3955
- const file = new Parse . File ( 'popeye.txt' , [ 1 , 2 , 3 ] , 'text/plain' ) ;
3956
- await file . save ( { useMasterKey : true } ) ;
3957
- await new Parse . File ( 'popeye.txt' , [ 1 , 2 , 3 ] , 'text/plain' ) . destroy ( { useMasterKey : true } ) ;
3958
- await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
3959
- for ( const key in triggers ) {
3960
- expect ( triggers [ key ] ) . toHaveBeenCalled ( ) ;
3961
- expect ( logSpy ) . toHaveBeenCalledWith (
3962
- `DeprecationWarning: Parse.Cloud.${ key } is deprecated and will be removed in a future version. Use Parse.Cloud.${ key . replace (
3963
- 'File' ,
3964
- ''
3965
- ) } (Parse.File, (request) => {})`
3966
- ) ;
3967
- }
3968
- } ) ;
3969
3920
} ) ;
3970
3921
3971
3922
describe ( 'sendEmail' , ( ) => {
0 commit comments