@webitel/api-services 26.8.26 → 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,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),
|