diff --git a/packages/lib/har/harUtils.spec.ts b/packages/lib/har/harUtils.spec.ts index ffe97c5..54e1c5d 100644 --- a/packages/lib/har/harUtils.spec.ts +++ b/packages/lib/har/harUtils.spec.ts @@ -9,6 +9,7 @@ import { toHarHttpVersion, toHarPostData, toHarQueryString, + checkMimeTypeListAndParseBody, } from './harUtils'; describe('harUtils', () => { @@ -244,6 +245,30 @@ describe('harUtils', () => { }); }); + describe('checkMimeTypeListAndParseBody', () => { + it('should return text if cant parse JSON', () => { + const content = 'Hello!'; + const returned = checkMimeTypeListAndParseBody( + ['application/json'], + content, + 'application/json', + ); + expect(returned).toEqual({ + mimeType: 'application/json', + text: content, + }); + }); + + it('should parse json if no mimeType is passed and mimeTypeList contains empty string', () => { + const content = '{"test": "hello"}'; + const returned = checkMimeTypeListAndParseBody([''], content); + expect(returned).toEqual({ + mimeType: undefined, + json: { test: 'hello' }, + }); + }); + }); + describe('version', () => { it('should work with no version', () => { expect(toHarHttpVersion()).toEqual('HTTP/1.1'); diff --git a/packages/lib/har/harUtils.ts b/packages/lib/har/harUtils.ts index 611a818..29cd9ed 100644 --- a/packages/lib/har/harUtils.ts +++ b/packages/lib/har/harUtils.ts @@ -96,7 +96,7 @@ export const fromHarContent = (content?: HarFormatContent) => { return Buffer.alloc(0); }; -const checkMimeTypeListAndParseBody = ( +export const checkMimeTypeListAndParseBody = ( parseMimeTypesAsJson: string[], body: string | Buffer, mimeType?: string,