@@ -21,13 +21,27 @@ const putObjectTaggingMock = jest.fn().mockResolvedValue({
21
21
Success : "Tags have been applied!" ,
22
22
} ) ;
23
23
24
+ const endpointMock = jest . fn ( ) . mockResolvedValue ( {
25
+ hostname : "s3.region.amazonaws.com" ,
26
+ port : undefined ,
27
+ protocol : "https:" ,
28
+ path : "/" ,
29
+ query : undefined ,
30
+ } ) ;
31
+
24
32
jest . mock ( "@aws-sdk/client-s3" , ( ) => ( {
25
33
...( jest . requireActual ( "@aws-sdk/client-s3" ) as { } ) ,
26
34
S3 : jest . fn ( ) . mockReturnValue ( {
27
35
send : sendMock ,
36
+ config : {
37
+ endpoint : endpointMock ,
38
+ } ,
28
39
} ) ,
29
40
S3Client : jest . fn ( ) . mockReturnValue ( {
30
41
send : sendMock ,
42
+ config : {
43
+ endpoint : endpointMock ,
44
+ } ,
31
45
} ) ,
32
46
CreateMultipartUploadCommand : createMultipartMock ,
33
47
UploadPartCommand : uploadPartMock ,
@@ -36,7 +50,7 @@ jest.mock("@aws-sdk/client-s3", () => ({
36
50
PutObjectCommand : putObjectMock ,
37
51
} ) ) ;
38
52
39
- import { S3 } from "@aws-sdk/client-s3" ;
53
+ import { CompleteMultipartUploadCommandOutput , S3 } from "@aws-sdk/client-s3" ;
40
54
import { Readable } from "stream" ;
41
55
42
56
import { Progress , Upload } from "./index" ;
@@ -184,6 +198,34 @@ describe(Upload.name, () => {
184
198
expect ( putObjectTaggingMock ) . toHaveBeenCalledTimes ( 0 ) ;
185
199
} ) ;
186
200
201
+ it ( "should return a Bucket, Key and Location fields when upload uses a PUT" , async ( ) => {
202
+ const buffer = Buffer . from ( "" ) ;
203
+ const actionParams = { ...params , Body : buffer } ;
204
+ const upload = new Upload ( {
205
+ params : actionParams ,
206
+ client : new S3 ( { } ) ,
207
+ } ) ;
208
+
209
+ const result = ( await upload . done ( ) ) as CompleteMultipartUploadCommandOutput ;
210
+ expect ( result . Key ) . toEqual ( "example-key" ) ;
211
+ expect ( result . Bucket ) . toEqual ( "example-bucket" ) ;
212
+ expect ( result . Location ) . toEqual ( "https://example-bucket.s3.region.amazonaws.com/example-key" ) ;
213
+ } ) ;
214
+
215
+ it ( "should return a Location field formatted in path style when forcePathStyle is true" , async ( ) => {
216
+ const buffer = Buffer . from ( "" ) ;
217
+ const actionParams = { ...params , Body : buffer } ;
218
+ const s3Client = new S3 ( { } ) ;
219
+ s3Client . config . forcePathStyle = true ;
220
+ const upload = new Upload ( {
221
+ params : actionParams ,
222
+ client : s3Client ,
223
+ } ) ;
224
+
225
+ const result = ( await upload . done ( ) ) as CompleteMultipartUploadCommandOutput ;
226
+ expect ( result . Location ) . toEqual ( "https://s3.region.amazonaws.com/example-bucket/example-key" ) ;
227
+ } ) ;
228
+
187
229
it ( "should upload using multi-part when parts are larger than part size" , async ( ) => {
188
230
// create a string that's larger than 5MB.
189
231
const partSize = 1024 * 1024 * 5 ;
0 commit comments