2024-02-01 12:09:28 +01:00
|
|
|
import fs from "fs"
|
|
|
|
import { join } from "path"
|
|
|
|
|
2023-01-25 13:06:10 +01:00
|
|
|
module AwsMock {
|
|
|
|
const aws: any = {}
|
|
|
|
|
2024-02-01 12:09:28 +01:00
|
|
|
const response = (body: any, extra?: any) => () => ({
|
|
|
|
promise: () => body,
|
|
|
|
...extra,
|
|
|
|
})
|
2023-01-25 13:06:10 +01:00
|
|
|
|
|
|
|
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({
|
2023-01-26 18:18:49 +01:00
|
|
|
Contents: [],
|
2023-01-25 13:06:10 +01:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
// @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: {},
|
|
|
|
})
|
|
|
|
)
|
2023-10-30 18:41:08 +01:00
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
this.getObject = jest.fn(
|
2024-02-01 12:09:28 +01:00
|
|
|
response(
|
|
|
|
{
|
|
|
|
Body: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
createReadStream: jest
|
|
|
|
.fn()
|
|
|
|
.mockReturnValue(
|
|
|
|
fs.createReadStream(join(__dirname, "aws-sdk.ts"))
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
2023-10-30 18:41:08 +01:00
|
|
|
)
|
2023-01-25 13:06:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
aws.DynamoDB = { DocumentClient }
|
|
|
|
aws.S3 = S3
|
|
|
|
aws.config = { update: jest.fn() }
|
|
|
|
|
|
|
|
module.exports = aws
|
|
|
|
}
|