@webitel/api-services 26.8.25 → 26.8.27

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.25",
3
+ "version": "26.8.27",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -157,7 +157,7 @@ const getList = async (params: ApiParams) => {
157
157
  }
158
158
  };
159
159
 
160
- const contactFieldsToSend = [
160
+ export const contactFieldsToSend = [
161
161
  'name',
162
162
  'about',
163
163
  'labels',
@@ -172,12 +172,14 @@ const contactFieldsToSend = [
172
172
  'imclients',
173
173
  'user',
174
174
  'custom',
175
- ];
175
+ ] as const;
176
176
 
177
177
  const get = async ({ itemId: id }: GetItemParams) => {
178
178
  try {
179
179
  const response = await getContacts().locateContact(String(id), {
180
- fields: contactFieldsToSend,
180
+ fields: [
181
+ ...contactFieldsToSend,
182
+ ],
181
183
  });
182
184
  return applyTransform(response.data, [
183
185
  snakeToCamel([
@@ -322,7 +324,9 @@ const update = async ({ itemInstance }: AddItemParams) => {
322
324
  ]);
323
325
  try {
324
326
  const response = await getContacts().updateContact(etag, item, {
325
- fields: contactFieldsToSend,
327
+ fields: [
328
+ ...contactFieldsToSend,
329
+ ],
326
330
  });
327
331
  return applyTransform(response.data, [
328
332
  snakeToCamel([
@@ -1,3 +1,4 @@
1
+ import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
1
2
  import { describe, expect, it } from 'vitest';
2
3
  import type { z } from 'zod';
3
4
  import {
@@ -602,6 +603,41 @@ describe('calendarSchema', () => {
602
603
 
603
604
  expect(result.success).toBe(true);
604
605
  });
606
+
607
+ /** [WTEL-10431](https://webitel.atlassian.net/browse/WTEL-10431) */
608
+ it('defaults both ends to the current day when omitted', () => {
609
+ const before = Date.now();
610
+ const result = calendarSchema.parse(minimalValidInput);
611
+ const after = Date.now();
612
+
613
+ expect(result.startAt).toBeGreaterThanOrEqual(before);
614
+ expect(result.startAt).toBeLessThanOrEqual(after);
615
+ expect(result.endAt).toBeGreaterThanOrEqual(before);
616
+ expect(result.endAt).toBeLessThanOrEqual(after);
617
+ });
618
+
619
+ /** an empty draft still seeds the pickers, even though `name` is missing */
620
+ it('seeds a blank draft with the current day', () => {
621
+ const before = Date.now();
622
+ const result = getDefaultsFromZodSchema(calendarSchema, {}) as {
623
+ startAt: number;
624
+ endAt: number;
625
+ };
626
+
627
+ expect(result.startAt).toBeGreaterThanOrEqual(before);
628
+ expect(result.endAt).toBeGreaterThanOrEqual(before);
629
+ });
630
+
631
+ it('keeps a null explicitly set on the draft', () => {
632
+ const result = calendarSchema.parse({
633
+ ...minimalValidInput,
634
+ startAt: null,
635
+ endAt: null,
636
+ });
637
+
638
+ expect(result.startAt).toBeNull();
639
+ expect(result.endAt).toBeNull();
640
+ });
605
641
  });
606
642
 
607
643
  describe('negative cases', () => {
@@ -195,6 +195,15 @@ const defaultSpecials = () =>
195
195
  }),
196
196
  );
197
197
 
198
+ /**
199
+ * A new temporary calendar opens on the current day: the `expires` switcher
200
+ * reveals the pickers already filled, instead of two empty required-looking
201
+ * fields. Matches the same fallback the API mapper applies to a stored calendar.
202
+ *
203
+ * [WTEL-10431](https://webitel.atlassian.net/browse/WTEL-10431)
204
+ */
205
+ const today = () => Date.now();
206
+
198
207
  export const calendarSchema = z.object<
199
208
  ZodShape<EngineCalendar> & {
200
209
  expires?: z.ZodType;
@@ -205,8 +214,8 @@ export const calendarSchema = z.object<
205
214
  name: z.string().min(1),
206
215
  description: z.string().optional().default(''),
207
216
  timezone: requiredLookupSchema,
208
- startAt: z.any().optional(),
209
- endAt: z.any().optional(),
217
+ startAt: z.any().optional().default(today),
218
+ endAt: z.any().optional().default(today),
210
219
  expires: z.boolean().optional().default(false),
211
220
  accepts: acceptsOfDayUiArraySchema.default(defaultAccepts),
212
221
  specials: acceptsOfDayUiArraySchema.default(defaultSpecials),