From 0f42ce4deccc19e59484c5ba6fe735871efd8baa Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Wed, 13 Mar 2024 08:09:13 -0500 Subject: [PATCH] Add bodyParser tests --- .../jsonBodyParser/jsonBodyParser.ts | 4 ++-- .../spec/jsonBodyParser.spec.ts | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/middleware/jsonBodyParser/jsonBodyParser.ts b/src/middleware/jsonBodyParser/jsonBodyParser.ts index 92d0a39..fdd36ea 100644 --- a/src/middleware/jsonBodyParser/jsonBodyParser.ts +++ b/src/middleware/jsonBodyParser/jsonBodyParser.ts @@ -26,8 +26,8 @@ export const DefaultJsonBodyParserOptions: OptionsJson = { * @returns The combined JSON Body Parser options with the supplied values taking * precedence over the default */ -export const getJsonBodyParserOptions = (options: Partial): OptionsJson => { - return { ...DefaultJsonBodyParserOptions, ...options } +export const getJsonBodyParserOptions = (options?: Partial): OptionsJson => { + return options ? { ...DefaultJsonBodyParserOptions, ...options } : DefaultJsonBodyParserOptions } /** diff --git a/src/middleware/jsonBodyParser/spec/jsonBodyParser.spec.ts b/src/middleware/jsonBodyParser/spec/jsonBodyParser.spec.ts index e69de29..b15759b 100644 --- a/src/middleware/jsonBodyParser/spec/jsonBodyParser.spec.ts +++ b/src/middleware/jsonBodyParser/spec/jsonBodyParser.spec.ts @@ -0,0 +1,20 @@ +import { DefaultJsonBodyParserOptions, getJsonBodyParserOptions } from '../jsonBodyParser' + +describe('jsonBodyParser', () => { + describe('getJsonBodyParserOptions', () => { + it('returns default options if none supplied', () => { + // Act + const result = getJsonBodyParserOptions() + // Assert + expect(result).toEqual(DefaultJsonBodyParserOptions) + }) + it('returns merged options if options supplied', () => { + // Arrange + const options = { limit: '1mb' } + // Act + const result = getJsonBodyParserOptions(options) + // Assert + expect(result).toEqual({ ...DefaultJsonBodyParserOptions, ...options }) + }) + }) +})