1+ import { setTimeout } from 'node:timers/promises' ;
12import { describe , expect , it } from 'vitest' ;
23import { validator } from '../../src/decorator.js' ;
34import { SchemaValidationError } from '../../src/errors.js' ;
@@ -21,11 +22,12 @@ const outboundSchema = {
2122} ;
2223
2324describe ( 'Decorator: validator' , ( ) => {
24- it ( 'should validate inbound and outbound successfully' , async ( ) => {
25+ it ( 'validates both inbound and outbound successfully' , async ( ) => {
2526 // Prepare
2627 class TestClass {
2728 @validator ( { inboundSchema, outboundSchema } )
2829 async multiply ( input : { value : number } ) : Promise < { result : number } > {
30+ await setTimeout ( 1 ) ; // simulate some processing time
2931 return { result : input . value * 2 } ;
3032 }
3133 }
@@ -39,11 +41,12 @@ describe('Decorator: validator', () => {
3941 expect ( output ) . toEqual ( { result : 10 } ) ;
4042 } ) ;
4143
42- it ( 'should throw error on inbound validation failure' , async ( ) => {
44+ it ( 'throws an error on inbound validation failure' , async ( ) => {
4345 // Prepare
4446 class TestClass {
4547 @validator ( { inboundSchema, outboundSchema } )
4648 async multiply ( input : { value : number } ) : Promise < { result : number } > {
49+ await setTimeout ( 1 ) ; // simulate some processing time
4750 return { result : input . value * 2 } ;
4851 }
4952 }
@@ -58,11 +61,12 @@ describe('Decorator: validator', () => {
5861 ) ;
5962 } ) ;
6063
61- it ( 'should throw error on outbound validation failure' , async ( ) => {
64+ it ( 'throws an error on outbound validation failure' , async ( ) => {
6265 // Prepare
6366 class TestClassInvalid {
6467 @validator ( { inboundSchema, outboundSchema } )
6568 async multiply ( _input : { value : number } ) {
69+ await setTimeout ( 1 ) ; // simulate some processing time
6670 return { result : 'invalid' } ;
6771 }
6872 }
@@ -74,11 +78,12 @@ describe('Decorator: validator', () => {
7478 ) ;
7579 } ) ;
7680
77- it ( 'should no-op when no schemas are provided' , async ( ) => {
81+ it ( 'results in a no-op when no schemas are provided' , async ( ) => {
7882 // Prepare
7983 class TestClassNoOp {
8084 @validator ( { } )
8185 async echo ( input : unknown ) : Promise < unknown > {
86+ await setTimeout ( 1 ) ; // simulate some processing time
8287 return input ;
8388 }
8489 }
@@ -92,11 +97,12 @@ describe('Decorator: validator', () => {
9297 expect ( result ) . toEqual ( data ) ;
9398 } ) ;
9499
95- it ( 'should validate inbound only' , async ( ) => {
100+ it ( 'validates the inbound schema only' , async ( ) => {
96101 // Prepare
97102 class TestClassInbound {
98103 @validator ( { inboundSchema } )
99104 async process ( input : { value : number } ) : Promise < { data : string } > {
105+ await setTimeout ( 1 ) ; // simulate some processing time
100106 return { data : JSON . stringify ( input ) } ;
101107 }
102108 }
@@ -110,11 +116,12 @@ describe('Decorator: validator', () => {
110116 expect ( output ) . toEqual ( { data : JSON . stringify ( input ) } ) ;
111117 } ) ;
112118
113- it ( 'should validate outbound only' , async ( ) => {
119+ it ( 'validates the outbound schema only' , async ( ) => {
114120 // Prepare
115121 class TestClassOutbound {
116122 @validator ( { outboundSchema } )
117123 async process ( _input : { text : string } ) : Promise < { result : number } > {
124+ await setTimeout ( 1 ) ; // simulate some processing time
118125 return { result : 42 } ;
119126 }
120127 }
0 commit comments