Skip to content

Commit

Permalink
docs: mocking lib-storage Upload for small files
Browse files Browse the repository at this point in the history
Fixes #228
  • Loading branch information
m-radzikowski committed Sep 23, 2024
1 parent 6d098fc commit 6ca4735
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,25 @@ const query = await ddb.send(new QueryCommand({

#### Lib Storage Upload

To mock `@aws-sdk/lib-storage` `Upload` you need to mock
at least two commands: `CreateMultipartUploadCommand` and `UploadPartCommand`
To mock `@aws-sdk/lib-storage` `Upload` you need to mock all commands
used [under the hood](https://github.com/aws/aws-sdk-js-v3/blob/main/lib/lib-storage/src/Upload.ts):

```typescript
import {S3Client, CreateMultipartUploadCommand, UploadPartCommand} from '@aws-sdk/client-s3';
import {Upload} from "@aws-sdk/lib-storage";

const s3Mock = mockClient(S3Client);

// for big files upload:
s3Mock.on(CreateMultipartUploadCommand).resolves({UploadId: '1'});
s3Mock.on(UploadPartCommand).resolves({ETag: '1'});

// for small files upload:
s3ClientMock.on(PutObjectCommand).callsFake(async (input, getClient) => {
getClient().config.endpoint = () => ({hostname: ""}) as any;
return {};
});

const s3Upload = new Upload({
client: new S3Client({}),
params: {
Expand Down

0 comments on commit 6ca4735

Please sign in to comment.