@webitel/api-services 26.8.16 → 26.8.17

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.16",
3
+ "version": "26.8.17",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,54 @@
1
+ import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { addDays } from 'date-fns';
3
+ import { describe, expect, it } from 'vitest';
4
+
5
+ import { queueMemberSchema } from '../queueMember.validations';
6
+
7
+ const filledCommunication = {
8
+ destination: '380000000000',
9
+ type: {
10
+ id: '1',
11
+ name: 'phone',
12
+ },
13
+ };
14
+
15
+ describe('queueMemberSchema', () => {
16
+ /** the card store seeds a new item from the schema defaults */
17
+ it('seeds a new member with the defaults the form expects', () => {
18
+ const defaults = getDefaultsFromZodSchema(queueMemberSchema, {}) as {
19
+ priority?: number;
20
+ expireAt?: number;
21
+ };
22
+
23
+ expect(defaults.priority).toBe(0);
24
+ expect(defaults.expireAt).toBeCloseTo(addDays(Date.now(), 7).getTime(), -4);
25
+ });
26
+
27
+ it('keeps values already on the draft', () => {
28
+ expect(
29
+ getDefaultsFromZodSchema(queueMemberSchema, {
30
+ name: 'member',
31
+ priority: 5,
32
+ expireAt: 1_700_000_000_000,
33
+ communications: [
34
+ filledCommunication,
35
+ ],
36
+ }),
37
+ ).toMatchObject({
38
+ priority: 5,
39
+ expireAt: 1_700_000_000_000,
40
+ });
41
+ });
42
+
43
+ it('still requires a name and a communication', () => {
44
+ const result = queueMemberSchema.safeParse({});
45
+
46
+ expect(result.success).toBe(false);
47
+ expect(result.error?.issues.map((issue) => issue.path.join('.'))).toEqual(
48
+ expect.arrayContaining([
49
+ 'name',
50
+ 'communications',
51
+ ]),
52
+ );
53
+ });
54
+ });
@@ -1,3 +1,4 @@
1
+ import { addDays } from 'date-fns';
1
2
  import { z } from 'zod';
2
3
 
3
4
  import { flexibleLookupSchema } from '../_shared/lookup.validations';
@@ -17,7 +18,7 @@ export const queueMemberSchema = z.object({
17
18
  name: z.string().min(1),
18
19
  /** legacy `requiredArrayValue` — a member with no way to reach it is useless */
19
20
  communications: z.array(memberCommunicationSchema).min(1),
20
- priority: z.number().optional(),
21
+ priority: z.number().optional().default(0),
21
22
  bucket: flexibleLookupSchema.optional(),
22
23
  timezone: flexibleLookupSchema.optional(),
23
24
  agent: flexibleLookupSchema.optional(),
@@ -26,7 +27,8 @@ export const queueMemberSchema = z.object({
26
27
  z.string(),
27
28
  z.number(),
28
29
  ])
29
- .optional(),
30
+ .optional()
31
+ .default(() => addDays(Date.now(), 7).getTime()),
30
32
  minOfferingAt: z
31
33
  .union([
32
34
  z.string(),