Skip to content

Commit 7e9bb9c

Browse files
authored
style(validation): apply stricter linting (#4565)
1 parent cfd57af commit 7e9bb9c

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

packages/validation/src/middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import { validate } from './validate.js';
105105
* @param options.ajv - Optional Ajv instance to use for validation, if not provided a new instance will be created.
106106
*/
107107
const validator = (options: ValidatorOptions) => {
108-
const before: MiddlewareFn = async (request) => {
108+
const before: MiddlewareFn = (request) => {
109109
if (options.inboundSchema) {
110110
const originalEvent = structuredClone(request.event);
111111
try {
@@ -125,7 +125,7 @@ const validator = (options: ValidatorOptions) => {
125125
}
126126
};
127127

128-
const after = async (handler: MiddyLikeRequest) => {
128+
const after = (handler: MiddyLikeRequest) => {
129129
if (options.outboundSchema) {
130130
try {
131131
handler.response = validate({

packages/validation/tests/unit/decorator.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setTimeout } from 'node:timers/promises';
12
import { describe, expect, it } from 'vitest';
23
import { validator } from '../../src/decorator.js';
34
import { SchemaValidationError } from '../../src/errors.js';
@@ -21,11 +22,12 @@ const outboundSchema = {
2122
};
2223

2324
describe('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
}

packages/validation/tests/unit/middleware.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const outboundSchema = {
2222
additionalProperties: false,
2323
};
2424

25-
const baseHandler = async (event: { inputValue: unknown }) => {
25+
const baseHandler = (event: { inputValue: unknown }) => {
2626
return {
2727
outputValue: event.inputValue,
2828
};

0 commit comments

Comments
 (0)