diff --git a/packages/server/__mocks__/aws-sdk.ts b/packages/server/__mocks__/aws-sdk.ts index 24873ac174..b0da0e97b6 100644 --- a/packages/server/__mocks__/aws-sdk.ts +++ b/packages/server/__mocks__/aws-sdk.ts @@ -44,6 +44,13 @@ module AwsMock { Contents: {}, }) ) + + // @ts-ignore + this.deleteObjects = jest.fn( + response({ + Contents: {}, + }) + ) } aws.DynamoDB = { DocumentClient } diff --git a/packages/server/src/integrations/s3.ts b/packages/server/src/integrations/s3.ts index b717ece222..72e664fe16 100644 --- a/packages/server/src/integrations/s3.ts +++ b/packages/server/src/integrations/s3.ts @@ -119,6 +119,19 @@ module S3Module { }, }, }, + delete: { + type: QueryType.FIELDS, + fields: { + bucket: { + type: DatasourceFieldType.STRING, + required: true, + }, + delete: { + type: DatasourceFieldType.JSON, + required: true, + }, + }, + } }, extra: { acl: { @@ -178,8 +191,7 @@ module S3Module { LocationConstraint: query.location, } } - const response = await this.client.createBucket(params).promise() - return response + return await this.client.createBucket(params).promise() } async read(query: { @@ -231,6 +243,15 @@ module S3Module { } }) } + + async delete(query: { bucket: string, delete: string }) { + return await this.client + .deleteObjects({ + Bucket: query.bucket, + Delete: JSON.parse(query.delete), + }) + .promise() + } } module.exports = { diff --git a/packages/server/src/integrations/tests/s3.spec.js b/packages/server/src/integrations/tests/s3.spec.js index 26a87fa99f..fc2477a225 100644 --- a/packages/server/src/integrations/tests/s3.spec.js +++ b/packages/server/src/integrations/tests/s3.spec.js @@ -74,4 +74,37 @@ describe("S3 Integration", () => { ACL: undefined, }) }) + + it("calls the delete method with the correct params ", async () => { + await config.integration.delete({ + bucket: "test", + delete: `{ + "Objects": [ + { + "Key": "HappyFace.jpg", + "VersionId": "2LWg7lQLnY41.maGB5Z6SWW.dcq0vx7b" + }, + { + "Key": "HappyFace.jpg", + "VersionId": "yoz3HB.ZhCS_tKVEmIOr7qYyyAaZSKVd" + } + ] + }` + }) + expect(config.integration.client.deleteObjects).toHaveBeenCalledWith({ + Bucket: "test", + Delete: { + Objects: [ + { + Key: "HappyFace.jpg", + VersionId: "2LWg7lQLnY41.maGB5Z6SWW.dcq0vx7b" + }, + { + Key: "HappyFace.jpg", + VersionId: "yoz3HB.ZhCS_tKVEmIOr7qYyyAaZSKVd" + } + ] + } + }) + }) }) \ No newline at end of file