I have a method which pulls from s3 and processed the gzipped file that is retrieved. I am attempting to write a test which mocks the retrieval (using a file read from the FS) and can then test the processing of the file.
The aws-sdk-client-mock is definitely the way to go an I have used it in other places, but having difficulty here the resolving the stream types.
import {mockClient} from "aws-sdk-client-mock";
const s3ClientMock = mockClient(S3Client);
test("getJSONFroms3Item returns data correctly with a gzip file from s3", async () => {
let stream: ReadStream = fs.createReadStream('../resources/persons.json.gz');
s3ClientMock.on(GetObjectCommand).resolves({ Body: stream});
const result = await getJSONFroms3Item();
expect(s3ClientMock).toHaveReceivedCommandWith(GetObjectCommand, {});
expect (result).toContain({name: "Jane Doe", address: "happytown", lastUpdated: 1657116641655, isActive: true, status:"ACTIVE"})
});
The error I am getting is
__test__/src/S3.test.ts:22:54 - error TS2322: Type 'ReadStream' is not assignable to type 'SdkStream<Readable | ReadableStream<any> | Blob | undefined> | undefined'.
Type 'ReadStream' is not assignable to type 'Readable & SdkStreamMixin'.
I have spent a long time trying to figure out how to get a Readable from the filesystem, but no luck.
I used the answer provided https://stackoverflow.com/a/72196278/10917982 to give me guidance, but can't see to get it working.
sandbox here https://taramcc-ominous-space-umbrella-7vq7j764xj9f799.github.dev/
Any help much appreciated.