From 273f244cd824d969d3ed70f63f21319681559f0f Mon Sep 17 00:00:00 2001 From: caroltrindade Date: Thu, 11 Apr 2024 16:11:53 +0200 Subject: [PATCH] chore: added test to s3 formatter --- __tests__/s3/formatters.test.ts | 30 ++++++++++++++++++++++++++++++ src/s3/index.ts | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 __tests__/s3/formatters.test.ts diff --git a/__tests__/s3/formatters.test.ts b/__tests__/s3/formatters.test.ts new file mode 100644 index 0000000..50cb6e1 --- /dev/null +++ b/__tests__/s3/formatters.test.ts @@ -0,0 +1,30 @@ +import { streamToString } from '../../src/s3' +import stream from 'stream' + +describe('streamToString', () => { + it('should convert a stream to a string', async () => { + const readable = new stream.Readable() + + readable._read = () => {} + readable.push('Hello, ') + readable.push('world!') + readable.push(null) + + const result = await streamToString(readable) + expect(result).toEqual('Hello, world!') + }) + + it('should convert a JSON stream to a string', async () => { + const json = { name: 'John Doe', age: 30 } + const jsonString = JSON.stringify(json) + const readable = new stream.Readable() + + readable._read = () => {} + readable.push(jsonString) + + const result = await streamToString(readable) + expect(result).toEqual(jsonString) + }) + + +}) diff --git a/src/s3/index.ts b/src/s3/index.ts index 25653d3..32901d8 100644 --- a/src/s3/index.ts +++ b/src/s3/index.ts @@ -1,2 +1,2 @@ export * from './s3Service' - +export * from './formatters'