@webitel/api-services 26.10.4 → 26.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { requiredDurationSchema } from '../duration.validations';
|
|
4
|
+
|
|
5
|
+
const tooSmallIssue = expect.objectContaining({
|
|
6
|
+
code: 'too_small',
|
|
7
|
+
minimum: 1,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('requiredDurationSchema', () => {
|
|
11
|
+
it.each([
|
|
12
|
+
1,
|
|
13
|
+
60,
|
|
14
|
+
'1',
|
|
15
|
+
'3600',
|
|
16
|
+
])('accepts %j', (value) => {
|
|
17
|
+
expect(requiredDurationSchema().safeParse(value).success).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it.each([
|
|
21
|
+
0,
|
|
22
|
+
'0',
|
|
23
|
+
'',
|
|
24
|
+
'abc',
|
|
25
|
+
])('rejects %j as too small', (value) => {
|
|
26
|
+
const result = requiredDurationSchema().safeParse(value);
|
|
27
|
+
|
|
28
|
+
expect(result.success).toBe(false);
|
|
29
|
+
expect(result.error?.issues).toEqual([
|
|
30
|
+
tooSmallIssue,
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it.each([
|
|
35
|
+
undefined,
|
|
36
|
+
null,
|
|
37
|
+
])('rejects missing %j', (value) => {
|
|
38
|
+
expect(requiredDurationSchema().safeParse(value).success).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('respects custom min', () => {
|
|
42
|
+
expect(requiredDurationSchema(60).safeParse('59').success).toBe(false);
|
|
43
|
+
expect(requiredDurationSchema(60).safeParse(60).success).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* [Claude] Duration may come as a numeric string (e.g. "0" from wt-timepicker),
|
|
5
|
+
* so compare the numeric value, not the string length.
|
|
6
|
+
*/
|
|
3
7
|
export const requiredDurationSchema = (min = 1) =>
|
|
4
|
-
z
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
z
|
|
9
|
+
.union([
|
|
10
|
+
z.string(),
|
|
11
|
+
z.number(),
|
|
12
|
+
])
|
|
13
|
+
.superRefine((value, ctx) => {
|
|
14
|
+
if (Number(value) >= min) return;
|
|
15
|
+
|
|
16
|
+
ctx.addIssue({
|
|
17
|
+
code: 'too_small',
|
|
18
|
+
origin: 'number',
|
|
19
|
+
minimum: min,
|
|
20
|
+
inclusive: true,
|
|
21
|
+
input: value,
|
|
22
|
+
});
|
|
23
|
+
});
|