Skip to content

Commit 27cacac

Browse files
committed
style(validation): apply stricter linting
1 parent 14dabe6 commit 27cacac

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

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

Lines changed: 29 additions & 18 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,29 +22,31 @@ const outboundSchema = {
2122
};
2223

2324
describe('Decorator: validator', () => {
24-
it('should validate inbound and outbound successfully', () => {
25+
it('validates both inbound and outbound successfully', async () => {
2526
// Prepare
2627
class TestClass {
2728
@validator({ inboundSchema, outboundSchema })
28-
multiply(input: { value: number }): { result: number } {
29+
async multiply(input: { value: number }): Promise<{ result: number }> {
30+
await setTimeout(1); // simulate some processing time
2931
return { result: input.value * 2 };
3032
}
3133
}
3234
const instance = new TestClass();
3335
const input = { value: 5 };
3436

3537
// Act
36-
const output = instance.multiply(input);
38+
const output = await instance.multiply(input);
3739

3840
// Assess
3941
expect(output).toEqual({ result: 10 });
4042
});
4143

42-
it('should throw error on inbound validation failure', () => {
44+
it('throws an error on inbound validation failure', async () => {
4345
// Prepare
4446
class TestClass {
4547
@validator({ inboundSchema, outboundSchema })
46-
multiply(input: { value: number }): { result: number } {
48+
async multiply(input: { value: number }): Promise<{ result: number }> {
49+
await setTimeout(1); // simulate some processing time
4750
return { result: input.value * 2 };
4851
}
4952
}
@@ -53,72 +56,80 @@ describe('Decorator: validator', () => {
5356
};
5457

5558
// Act & Assess
56-
expect(instance.multiply(invalidInput)).toThrow(SchemaValidationError);
59+
await expect(instance.multiply(invalidInput)).rejects.toThrow(
60+
SchemaValidationError
61+
);
5762
});
5863

59-
it('should throw error on outbound validation failure', () => {
64+
it('throws an error on outbound validation failure', async () => {
6065
// Prepare
6166
class TestClassInvalid {
6267
@validator({ inboundSchema, outboundSchema })
63-
multiply(_input: { value: number }) {
68+
async multiply(_input: { value: number }) {
69+
await setTimeout(1); // simulate some processing time
6470
return { result: 'invalid' };
6571
}
6672
}
6773
const instance = new TestClassInvalid();
6874

6975
// Act & Assess
70-
expect(instance.multiply({ value: 5 })).toThrow(SchemaValidationError);
76+
await expect(instance.multiply({ value: 5 })).rejects.toThrow(
77+
SchemaValidationError
78+
);
7179
});
7280

73-
it('should no-op when no schemas are provided', () => {
81+
it('results in a no-op when no schemas are provided', async () => {
7482
// Prepare
7583
class TestClassNoOp {
7684
@validator({})
77-
echo(input: unknown): unknown {
85+
async echo(input: unknown): Promise<unknown> {
86+
await setTimeout(1); // simulate some processing time
7887
return input;
7988
}
8089
}
8190
const instance = new TestClassNoOp();
8291
const data = { foo: 'bar' };
8392

8493
// Act
85-
const result = instance.echo(data);
94+
const result = await instance.echo(data);
8695

8796
// Assess
8897
expect(result).toEqual(data);
8998
});
9099

91-
it('should validate inbound only', () => {
100+
it('validates the inbound schema only', async () => {
92101
// Prepare
93102
class TestClassInbound {
94103
@validator({ inboundSchema })
95-
process(input: { value: number }): { data: string } {
104+
async process(input: { value: number }): Promise<{ data: string }> {
105+
await setTimeout(1); // simulate some processing time
96106
return { data: JSON.stringify(input) };
97107
}
98108
}
99109
const instance = new TestClassInbound();
100110
const input = { value: 10 };
101111

102112
// Act
103-
const output = instance.process(input);
113+
const output = await instance.process(input);
104114

105115
// Assess
106116
expect(output).toEqual({ data: JSON.stringify(input) });
107117
});
108118

109-
it('should validate outbound only', () => {
119+
it('validates the outbound schema only', async () => {
110120
// Prepare
111121
class TestClassOutbound {
112122
@validator({ outboundSchema })
113-
process(_input: { text: string }): { result: number } {
123+
async process(_input: { text: string }): Promise<{ result: number }> {
124+
await setTimeout(1); // simulate some processing time
114125
return { result: 42 };
115126
}
116127
}
117128
const instance = new TestClassOutbound();
118129
const input = { text: 'hello' };
119130

120131
// Act
121-
const output = instance.process(input);
132+
const output = await instance.process(input);
122133

123134
// Assess
124135
expect(output).toEqual({ result: 42 });

0 commit comments

Comments
 (0)