2024-02-01 12:09:28 +01:00
|
|
|
import fs from "fs"
|
|
|
|
import { join } from "path"
|
|
|
|
|
2024-03-19 17:50:48 +01:00
|
|
|
const response = (body: any, extra?: any) => () => ({
|
|
|
|
promise: () => body,
|
|
|
|
...extra,
|
|
|
|
})
|
2023-01-25 13:06:10 +01:00
|
|
|
|
2024-03-19 17:50:48 +01:00
|
|
|
class DocumentClient {
|
|
|
|
put = jest.fn(response({}))
|
|
|
|
query = jest.fn(
|
|
|
|
response({
|
|
|
|
Items: [],
|
|
|
|
})
|
|
|
|
)
|
|
|
|
scan = jest.fn(
|
|
|
|
response({
|
|
|
|
Items: [
|
2024-02-01 12:09:28 +01:00
|
|
|
{
|
2024-03-19 17:50:48 +01:00
|
|
|
Name: "test",
|
2024-02-01 12:09:28 +01:00
|
|
|
},
|
2024-03-19 17:50:48 +01:00
|
|
|
],
|
|
|
|
})
|
|
|
|
)
|
|
|
|
get = jest.fn(response({}))
|
|
|
|
update = jest.fn(response({}))
|
|
|
|
delete = jest.fn(response({}))
|
|
|
|
}
|
2023-01-25 13:06:10 +01:00
|
|
|
|
2024-03-19 17:50:48 +01:00
|
|
|
class S3 {
|
|
|
|
listObjects = jest.fn(
|
|
|
|
response({
|
|
|
|
Contents: [],
|
|
|
|
})
|
|
|
|
)
|
|
|
|
createBucket = jest.fn(
|
|
|
|
response({
|
|
|
|
Contents: {},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
deleteObjects = jest.fn(
|
|
|
|
response({
|
|
|
|
Contents: {},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
getSignedUrl = jest.fn((operation, params) => {
|
|
|
|
return `http://example.com/${params.Bucket}/${params.Key}`
|
|
|
|
})
|
|
|
|
headBucket = jest.fn(
|
|
|
|
response({
|
|
|
|
Contents: {},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
upload = jest.fn(
|
|
|
|
response({
|
|
|
|
Contents: {},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
getObject = jest.fn(
|
|
|
|
response(
|
|
|
|
{
|
|
|
|
Body: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
createReadStream: jest
|
|
|
|
.fn()
|
|
|
|
.mockReturnValue(fs.createReadStream(join(__dirname, "aws-sdk.ts"))),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2023-01-25 13:06:10 +01:00
|
|
|
|
2024-03-19 17:50:48 +01:00
|
|
|
module.exports = {
|
|
|
|
DynamoDB: {
|
|
|
|
DocumentClient,
|
|
|
|
},
|
|
|
|
S3,
|
|
|
|
config: {
|
|
|
|
update: jest.fn(),
|
|
|
|
},
|
2023-01-25 13:06:10 +01:00
|
|
|
}
|