Testing an s3 upload? The method to test is
export class ProcessData {
constructor() {}
async process(): Promise<void> {
const data = await s3Client.send(new GetObjectCommand(bucket));
await parseCsvData(data.Body)
}
This is my attempt at the test case.
import {S3Client} from '@aws-sdk/client-s3';
jest.mock("aws-sdk/clients/s3", () => {
return {
S3Client: jest.fn(() => {
send: jest.fn().mockImplementation(() => {
data: Buffer.from(require("fs").readFileSync(path.resolve(__dirname, "test.csv")));
})
})
}
});
describe("@aws-sdk/client-s3 mock", () => {
test('CSV Happy path', async () => {
const processData = new ProcessData()
await processData.process()
}
}
The process gets to the parse method and throws an error "The bucket you are attempting to access must be addressed using the specific endpoint"