Delete method S3 Bucket

This commit is contained in:
Mel O'Hagan 2022-08-30 19:56:08 +01:00
parent 088cf26b46
commit 0e44703e95
3 changed files with 63 additions and 2 deletions

View File

@ -44,6 +44,13 @@ module AwsMock {
Contents: {},
})
)
// @ts-ignore
this.deleteObjects = jest.fn(
response({
Contents: {},
})
)
}
aws.DynamoDB = { DocumentClient }

View File

@ -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 = {

View File

@ -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"
}
]
}
})
})
})