@webitel/api-services 26.8.14 → 26.8.15

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/api-services",
3
- "version": "26.8.14",
3
+ "version": "26.8.15",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ import { i18nIssue } from '../_shared/i18nIssue';
4
+
3
5
  export const caseCloseSchema = z
4
6
  .object({
5
7
  reason: z
@@ -17,12 +19,20 @@ export const caseCloseSchema = z
17
19
  if (!data.reason?.id) {
18
20
  ctx.addIssue({
19
21
  code: 'custom',
22
+ path: [
23
+ 'reason',
24
+ ],
25
+ ...i18nIssue('required'),
20
26
  });
21
27
  }
22
28
 
23
29
  if (!data.result) {
24
30
  ctx.addIssue({
25
31
  code: 'custom',
32
+ path: [
33
+ 'result',
34
+ ],
35
+ ...i18nIssue('required'),
26
36
  });
27
37
  }
28
38
  });
@@ -0,0 +1,80 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { z } from 'zod';
3
+
4
+ import { caseExportOptionsSchema } from '../caseExportOptions.validations';
5
+
6
+ const issues = (result: z.ZodSafeParseResult<unknown>) =>
7
+ result.success
8
+ ? []
9
+ : result.error.issues.map((issue) => ({
10
+ path: issue.path.join('.'),
11
+ i18nKey: (
12
+ issue as {
13
+ params?: {
14
+ i18nKey?: string;
15
+ };
16
+ }
17
+ ).params?.i18nKey,
18
+ }));
19
+
20
+ describe('caseExportOptionsSchema', () => {
21
+ it('accepts xlsx without a separator', () => {
22
+ const result = caseExportOptionsSchema.safeParse({
23
+ type: {
24
+ name: 'xlsx',
25
+ value: 'xlsx',
26
+ },
27
+ separator: null,
28
+ });
29
+
30
+ expect(issues(result)).toEqual([]);
31
+ });
32
+
33
+ it('accepts csv with a separator', () => {
34
+ const result = caseExportOptionsSchema.safeParse({
35
+ type: {
36
+ name: 'csv',
37
+ value: 'csv',
38
+ },
39
+ separator: ',',
40
+ });
41
+
42
+ expect(issues(result)).toEqual([]);
43
+ });
44
+
45
+ /**
46
+ * The popup binds `r$.$fields.type` to the select, so the issue has to be
47
+ * filed under `type` — a root-level issue disables the button but shows no
48
+ * "required" message under the field (WTEL-10340).
49
+ */
50
+ it('reports a missing format under the `type` path', () => {
51
+ const result = caseExportOptionsSchema.safeParse({
52
+ type: null,
53
+ separator: ',',
54
+ });
55
+
56
+ expect(issues(result)).toEqual([
57
+ {
58
+ path: 'type',
59
+ i18nKey: 'required',
60
+ },
61
+ ]);
62
+ });
63
+
64
+ it('reports a missing csv separator under the `separator` path', () => {
65
+ const result = caseExportOptionsSchema.safeParse({
66
+ type: {
67
+ name: 'csv',
68
+ value: 'csv',
69
+ },
70
+ separator: '',
71
+ });
72
+
73
+ expect(issues(result)).toEqual([
74
+ {
75
+ path: 'separator',
76
+ i18nKey: 'required',
77
+ },
78
+ ]);
79
+ });
80
+ });
@@ -1,5 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ import { i18nIssue } from '../_shared/i18nIssue';
4
+
3
5
  export const caseExportOptionsSchema = z
4
6
  .object({
5
7
  type: z
@@ -14,12 +16,20 @@ export const caseExportOptionsSchema = z
14
16
  if (!data.type) {
15
17
  ctx.addIssue({
16
18
  code: 'custom',
19
+ path: [
20
+ 'type',
21
+ ],
22
+ ...i18nIssue('required'),
17
23
  });
18
24
  }
19
25
 
20
26
  if (data.type?.value === 'csv' && !data.separator) {
21
27
  ctx.addIssue({
22
28
  code: 'custom',
29
+ path: [
30
+ 'separator',
31
+ ],
32
+ ...i18nIssue('required'),
23
33
  });
24
34
  }
25
35
  });