From b0ba9505d59c1ebd25afda443963f8011cf916f1 Mon Sep 17 00:00:00 2001 From: Matthew Warman Date: Tue, 14 Nov 2023 13:44:39 -0500 Subject: [PATCH] SLSCMN-4 joi validator tests --- src/middlewares/validator-joi.test.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/middlewares/validator-joi.test.ts b/src/middlewares/validator-joi.test.ts index fd88a57..8f311d9 100644 --- a/src/middlewares/validator-joi.test.ts +++ b/src/middlewares/validator-joi.test.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { Request } from '@middy/core'; import * as Joi from 'joi'; import { BadRequestError } from '../errors/bad-request.error'; @@ -5,7 +6,7 @@ import { BadRequestError } from '../errors/bad-request.error'; import { validator } from './validator-joi'; import { requestFixture } from '../__fixtures__/middy.fixture'; -describe('validator-joi', () => { +describe('JoiValidator', () => { const schema = Joi.object({ s: Joi.string().required(), b: Joi.boolean().default(false), @@ -18,6 +19,25 @@ describe('validator-joi', () => { expect(middleware.before).toBeDefined(); }); + it('should write log when logger provided', () => { + type loggerFn = (msg: string) => void; + const mockLogger = jest.fn(); + + const request: Request = { + ...requestFixture, + event: { + s: 'string', + b: 'true', + n: '100', + }, + }; + const middleware = validator({ eventSchema: schema, logger: mockLogger }); + + middleware.before?.(request); + + expect(mockLogger).toHaveBeenCalled(); + }); + it('should validate successfully', () => { const request: Request = { ...requestFixture,