From 13af7aa7307f5028a05804633aa7ab7b3251d691 Mon Sep 17 00:00:00 2001 From: Adria Navarro Redo Date: Wed, 25 Jan 2023 12:06:10 +0000 Subject: [PATCH] Add aws-sdk mock back --- packages/server/__mocks__/aws-sdk.ts | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 packages/server/__mocks__/aws-sdk.ts diff --git a/packages/server/__mocks__/aws-sdk.ts b/packages/server/__mocks__/aws-sdk.ts new file mode 100644 index 0000000000..2efbd303f2 --- /dev/null +++ b/packages/server/__mocks__/aws-sdk.ts @@ -0,0 +1,80 @@ +module AwsMock { + const aws: any = {} + + const response = (body: any) => () => ({ promise: () => body }) + + function DocumentClient() { + // @ts-ignore + this.put = jest.fn(response({})) + // @ts-ignore + this.query = jest.fn( + response({ + Items: [], + }) + ) + // @ts-ignore + this.scan = jest.fn( + response({ + Items: [ + { + Name: "test", + }, + ], + }) + ) + // @ts-ignore + this.get = jest.fn(response({})) + // @ts-ignore + this.update = jest.fn(response({})) + // @ts-ignore + this.delete = jest.fn(response({})) + } + + function S3() { + // @ts-ignore + this.listObjects = jest.fn( + response({ + Contents: {}, + }) + ) + + // @ts-ignore + this.createBucket = jest.fn( + response({ + Contents: {}, + }) + ) + + // @ts-ignore + this.deleteObjects = jest.fn( + response({ + Contents: {}, + }) + ) + + // @ts-ignore + this.getSignedUrl = (operation, params) => { + return `http://test.com/${params.Bucket}/${params.Key}` + } + + // @ts-ignore + this.headBucket = jest.fn( + response({ + Contents: {}, + }) + ) + + // @ts-ignore + this.upload = jest.fn( + response({ + Contents: {}, + }) + ) + } + + aws.DynamoDB = { DocumentClient } + aws.S3 = S3 + aws.config = { update: jest.fn() } + + module.exports = aws +}