From 6ca47357f75e31a03a371df943130066cd8cfe4a Mon Sep 17 00:00:00 2001 From: Maciej Radzikowski Date: Mon, 23 Sep 2024 17:58:26 +0200 Subject: [PATCH] docs: mocking lib-storage Upload for small files Fixes #228 --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a0f57e..89fe9e2 100644 --- a/README.md +++ b/README.md @@ -306,8 +306,7 @@ 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 @@ -315,9 +314,17 @@ import {S3Client, CreateMultipartUploadCommand, UploadPartCommand} from '@aws-sd 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: {