@@ -3615,16 +3615,16 @@ describe("Test file uploading", () => {
3615
3615
actions : {
3616
3616
save ( ctx ) {
3617
3617
return new this . Promise ( ( resolve ) => {
3618
- if ( ctx . params . pipe ) {
3618
+ if ( ctx . stream && ctx . stream . pipe ) {
3619
3619
const hash = crypto . createHash ( "sha256" ) ;
3620
3620
3621
3621
hash . on ( "readable" , ( ) => {
3622
3622
const data = hash . read ( ) ;
3623
3623
if ( data )
3624
- resolve ( { hash : data . toString ( "base64" ) , meta : ctx . meta } ) ;
3624
+ resolve ( { hash : data . toString ( "base64" ) , params : ctx . params , meta : ctx . meta } ) ;
3625
3625
} ) ;
3626
3626
3627
- ctx . params . pipe ( hash ) ;
3627
+ ctx . stream . pipe ( hash ) ;
3628
3628
} else {
3629
3629
resolve ( { params : ctx . params , meta : ctx . meta } ) ;
3630
3630
}
@@ -3722,14 +3722,12 @@ describe("Test file uploading", () => {
3722
3722
. then ( res => {
3723
3723
expect ( res . statusCode ) . toBe ( 200 ) ;
3724
3724
expect ( res . headers [ "content-type" ] ) . toBe ( "application/json; charset=utf-8" ) ;
3725
- expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , meta : {
3726
- $multipart : { } ,
3727
- $params : { } ,
3728
- encoding : "7bit" ,
3729
- fieldname : "myFile" ,
3730
- filename : "logo.png" ,
3731
- mimetype : "image/png"
3732
- } } ) ;
3725
+ expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , params : {
3726
+ $encoding : "7bit" ,
3727
+ $fieldname : "myFile" ,
3728
+ $filename : "logo.png" ,
3729
+ $mimetype : "image/png"
3730
+ } , meta : { } } ) ;
3733
3731
3734
3732
expect ( onFilesLimitFn ) . toHaveBeenCalledTimes ( 0 ) ;
3735
3733
} ) ;
@@ -3738,21 +3736,18 @@ describe("Test file uploading", () => {
3738
3736
it ( "should send data field with multipart" , ( ) => {
3739
3737
return request ( server )
3740
3738
. post ( "/upload" )
3741
- . attach ( "myFile" , assetsDir + "logo.png" )
3742
3739
. field ( "name" , "moleculer" )
3740
+ . attach ( "myFile" , assetsDir + "logo.png" )
3743
3741
. then ( res => {
3744
3742
expect ( res . statusCode ) . toBe ( 200 ) ;
3745
3743
expect ( res . headers [ "content-type" ] ) . toBe ( "application/json; charset=utf-8" ) ;
3746
- expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , meta : {
3747
- $multipart : {
3748
- name : "moleculer"
3749
- } ,
3750
- $params : { } ,
3751
- encoding : "7bit" ,
3752
- fieldname : "myFile" ,
3753
- filename : "logo.png" ,
3754
- mimetype : "image/png"
3755
- } } ) ;
3744
+ expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , params : {
3745
+ name : "moleculer" ,
3746
+ $encoding : "7bit" ,
3747
+ $fieldname : "myFile" ,
3748
+ $filename : "logo.png" ,
3749
+ $mimetype : "image/png"
3750
+ } , meta : { } } ) ;
3756
3751
3757
3752
expect ( onFilesLimitFn ) . toHaveBeenCalledTimes ( 0 ) ;
3758
3753
} ) ;
@@ -3767,11 +3762,8 @@ describe("Test file uploading", () => {
3767
3762
expect ( res . statusCode ) . toBe ( 200 ) ;
3768
3763
expect ( res . headers [ "content-type" ] ) . toBe ( "application/json; charset=utf-8" ) ;
3769
3764
expect ( res . body ) . toEqual ( [ {
3770
- meta : {
3771
- $multipart : { name : "moleculer" , more : "services" } ,
3772
- $params : { id : "f1234" }
3773
- } ,
3774
- params : { }
3765
+ meta : { } ,
3766
+ params : { id : "f1234" , name : "moleculer" , more : "services" }
3775
3767
} ] ) ;
3776
3768
} ) ;
3777
3769
} ) ;
@@ -3784,14 +3776,12 @@ describe("Test file uploading", () => {
3784
3776
. then ( res => {
3785
3777
expect ( res . statusCode ) . toBe ( 200 ) ;
3786
3778
expect ( res . headers [ "content-type" ] ) . toBe ( "application/json; charset=utf-8" ) ;
3787
- expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , meta : {
3788
- $multipart : { } ,
3789
- $params : { } ,
3790
- encoding : "7bit" ,
3791
- fieldname : "myFile" ,
3792
- filename : "logo.png" ,
3793
- mimetype : "image/png"
3794
- } } ) ;
3779
+ expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , params : {
3780
+ $encoding : "7bit" ,
3781
+ $fieldname : "myFile" ,
3782
+ $filename : "logo.png" ,
3783
+ $mimetype : "image/png"
3784
+ } , meta : { } } ) ;
3795
3785
expect ( onFilesLimitFn ) . toHaveBeenCalledTimes ( 1 ) ;
3796
3786
expect ( onFilesLimitFn ) . toHaveBeenCalledWith ( expect . any ( Busboy ) , expect . any ( Alias ) , service ) ;
3797
3787
} ) ;
@@ -3806,22 +3796,18 @@ describe("Test file uploading", () => {
3806
3796
expect ( res . statusCode ) . toBe ( 200 ) ;
3807
3797
expect ( res . headers [ "content-type" ] ) . toBe ( "application/json; charset=utf-8" ) ;
3808
3798
expect ( res . body ) . toEqual ( [
3809
- { hash : origHashes [ "logo.png" ] , meta : {
3810
- $multipart : { } ,
3811
- $params : { } ,
3812
- encoding : "7bit" ,
3813
- fieldname : "myFile" ,
3814
- filename : "logo.png" ,
3815
- mimetype : "image/png"
3816
- } } ,
3817
- { hash : origHashes [ "lorem.txt" ] , meta : {
3818
- $multipart : { } ,
3819
- $params : { } ,
3820
- encoding : "7bit" ,
3821
- fieldname : "myText" ,
3822
- filename : "lorem.txt" ,
3823
- mimetype : "text/plain"
3824
- } }
3799
+ { hash : origHashes [ "logo.png" ] , params : {
3800
+ $encoding : "7bit" ,
3801
+ $fieldname : "myFile" ,
3802
+ $filename : "logo.png" ,
3803
+ $mimetype : "image/png"
3804
+ } , meta : { } } ,
3805
+ { hash : origHashes [ "lorem.txt" ] , params : {
3806
+ $encoding : "7bit" ,
3807
+ $fieldname : "myText" ,
3808
+ $filename : "lorem.txt" ,
3809
+ $mimetype : "text/plain"
3810
+ } , meta : { } }
3825
3811
] ) ;
3826
3812
} ) ;
3827
3813
} ) ;
@@ -3835,9 +3821,7 @@ describe("Test file uploading", () => {
3835
3821
. then ( res => {
3836
3822
expect ( res . statusCode ) . toBe ( 200 ) ;
3837
3823
expect ( res . headers [ "content-type" ] ) . toBe ( "application/json; charset=utf-8" ) ;
3838
- expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , meta : {
3839
- $params : { } ,
3840
- } } ) ;
3824
+ expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , params : { } , meta : { } } ) ;
3841
3825
} ) ;
3842
3826
3843
3827
} ) ;
@@ -3851,9 +3835,7 @@ describe("Test file uploading", () => {
3851
3835
. then ( res => {
3852
3836
expect ( res . statusCode ) . toBe ( 200 ) ;
3853
3837
expect ( res . headers [ "content-type" ] ) . toBe ( "application/json; charset=utf-8" ) ;
3854
- expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , meta : {
3855
- $params : { id : "f1234" } ,
3856
- } } ) ;
3838
+ expect ( res . body ) . toEqual ( { hash : origHashes [ "logo.png" ] , params : { id : "f1234" } , meta : { } } ) ;
3857
3839
} ) ;
3858
3840
} ) ;
3859
3841
0 commit comments