Skip to content

Commit

Permalink
Add bodyParser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Mar 13, 2024
1 parent 9596cac commit 0f42ce4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/middleware/jsonBodyParser/jsonBodyParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>): OptionsJson => {
return { ...DefaultJsonBodyParserOptions, ...options }
export const getJsonBodyParserOptions = (options?: Partial<OptionsJson>): OptionsJson => {
return options ? { ...DefaultJsonBodyParserOptions, ...options } : DefaultJsonBodyParserOptions
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/middleware/jsonBodyParser/spec/jsonBodyParser.spec.ts
Original file line number Diff line number Diff line change
@@ -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 })
})
})
})

0 comments on commit 0f42ce4

Please sign in to comment.