diff --git a/packages/validation/src/middleware.ts b/packages/validation/src/middleware.ts index af6d953033..59a5093c62 100644 --- a/packages/validation/src/middleware.ts +++ b/packages/validation/src/middleware.ts @@ -105,7 +105,7 @@ import { validate } from './validate.js'; * @param options.ajv - Optional Ajv instance to use for validation, if not provided a new instance will be created. */ const validator = (options: ValidatorOptions) => { - const before: MiddlewareFn = async (request) => { + const before: MiddlewareFn = (request) => { if (options.inboundSchema) { const originalEvent = structuredClone(request.event); try { @@ -125,7 +125,7 @@ const validator = (options: ValidatorOptions) => { } }; - const after = async (handler: MiddyLikeRequest) => { + const after = (handler: MiddyLikeRequest) => { if (options.outboundSchema) { try { handler.response = validate({ diff --git a/packages/validation/tests/unit/decorator.test.ts b/packages/validation/tests/unit/decorator.test.ts index 28e6cd27fd..423ab34cc6 100644 --- a/packages/validation/tests/unit/decorator.test.ts +++ b/packages/validation/tests/unit/decorator.test.ts @@ -1,3 +1,4 @@ +import { setTimeout } from 'node:timers/promises'; import { describe, expect, it } from 'vitest'; import { validator } from '../../src/decorator.js'; import { SchemaValidationError } from '../../src/errors.js'; @@ -21,11 +22,12 @@ const outboundSchema = { }; describe('Decorator: validator', () => { - it('should validate inbound and outbound successfully', async () => { + it('validates both inbound and outbound successfully', async () => { // Prepare class TestClass { @validator({ inboundSchema, outboundSchema }) async multiply(input: { value: number }): Promise<{ result: number }> { + await setTimeout(1); // simulate some processing time return { result: input.value * 2 }; } } @@ -39,11 +41,12 @@ describe('Decorator: validator', () => { expect(output).toEqual({ result: 10 }); }); - it('should throw error on inbound validation failure', async () => { + it('throws an error on inbound validation failure', async () => { // Prepare class TestClass { @validator({ inboundSchema, outboundSchema }) async multiply(input: { value: number }): Promise<{ result: number }> { + await setTimeout(1); // simulate some processing time return { result: input.value * 2 }; } } @@ -58,11 +61,12 @@ describe('Decorator: validator', () => { ); }); - it('should throw error on outbound validation failure', async () => { + it('throws an error on outbound validation failure', async () => { // Prepare class TestClassInvalid { @validator({ inboundSchema, outboundSchema }) async multiply(_input: { value: number }) { + await setTimeout(1); // simulate some processing time return { result: 'invalid' }; } } @@ -74,11 +78,12 @@ describe('Decorator: validator', () => { ); }); - it('should no-op when no schemas are provided', async () => { + it('results in a no-op when no schemas are provided', async () => { // Prepare class TestClassNoOp { @validator({}) async echo(input: unknown): Promise { + await setTimeout(1); // simulate some processing time return input; } } @@ -92,11 +97,12 @@ describe('Decorator: validator', () => { expect(result).toEqual(data); }); - it('should validate inbound only', async () => { + it('validates the inbound schema only', async () => { // Prepare class TestClassInbound { @validator({ inboundSchema }) async process(input: { value: number }): Promise<{ data: string }> { + await setTimeout(1); // simulate some processing time return { data: JSON.stringify(input) }; } } @@ -110,11 +116,12 @@ describe('Decorator: validator', () => { expect(output).toEqual({ data: JSON.stringify(input) }); }); - it('should validate outbound only', async () => { + it('validates the outbound schema only', async () => { // Prepare class TestClassOutbound { @validator({ outboundSchema }) async process(_input: { text: string }): Promise<{ result: number }> { + await setTimeout(1); // simulate some processing time return { result: 42 }; } } diff --git a/packages/validation/tests/unit/middleware.test.ts b/packages/validation/tests/unit/middleware.test.ts index 1d2796638a..6b76d66d65 100644 --- a/packages/validation/tests/unit/middleware.test.ts +++ b/packages/validation/tests/unit/middleware.test.ts @@ -22,7 +22,7 @@ const outboundSchema = { additionalProperties: false, }; -const baseHandler = async (event: { inputValue: unknown }) => { +const baseHandler = (event: { inputValue: unknown }) => { return { outputValue: event.inputValue, };