@webitel/api-services 1.0.7 → 1.0.9

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": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -262,6 +262,77 @@ describe('CalendarsAPI', () => {
262
262
  });
263
263
  });
264
264
 
265
+ it('treats omitted work_start on a working except as midnight (protobuf omits 0)', async () => {
266
+ mockCalendarService.readCalendar.mockResolvedValueOnce({
267
+ data: {
268
+ name: 'Cal',
269
+ timezone: {
270
+ id: 'tz-1',
271
+ },
272
+ excepts: [
273
+ {
274
+ name: 'ff',
275
+ date: 123,
276
+ repeat: true,
277
+ working: true,
278
+ work_stop: 1200,
279
+ },
280
+ ],
281
+ },
282
+ });
283
+
284
+ const result = await CalendarsAPI.get({
285
+ itemId: 1,
286
+ });
287
+
288
+ expect(result.excepts).toEqual([
289
+ {
290
+ name: 'ff',
291
+ date: 123,
292
+ repeat: true,
293
+ working: true,
294
+ workStart: 0,
295
+ workStop: 1200,
296
+ },
297
+ ]);
298
+ });
299
+
300
+ it('keeps midnight (0) holiday workStart/workStop instead of coercing to null', async () => {
301
+ mockCalendarService.readCalendar.mockResolvedValueOnce({
302
+ data: {
303
+ name: 'Cal',
304
+ timezone: {
305
+ id: 'tz-1',
306
+ },
307
+ excepts: [
308
+ {
309
+ name: 'holiday',
310
+ date: 123,
311
+ repeat: true,
312
+ working: true,
313
+ work_start: 0,
314
+ work_stop: 60,
315
+ },
316
+ ],
317
+ },
318
+ });
319
+
320
+ const result = await CalendarsAPI.get({
321
+ itemId: 1,
322
+ });
323
+
324
+ expect(result.excepts).toEqual([
325
+ {
326
+ name: 'holiday',
327
+ date: 123,
328
+ repeat: true,
329
+ working: true,
330
+ workStart: 0,
331
+ workStop: 60,
332
+ },
333
+ ]);
334
+ });
335
+
265
336
  it('defaults accepts to an empty array instead of throwing when missing', async () => {
266
337
  mockCalendarService.readCalendar.mockResolvedValueOnce({
267
338
  data: {
@@ -55,8 +55,8 @@ const mapCalendarToUi = (item: ApiParams) => {
55
55
  date: except.date || 0,
56
56
  repeat: except.repeat || false,
57
57
  working: except.working || false,
58
- workStart: except.workStart || null,
59
- workStop: except.workStop || null,
58
+ workStart: except.workStart ?? (except.working ? 0 : null),
59
+ workStop: except.workStop ?? (except.working ? 0 : null),
60
60
  }));
61
61
  }
62
62
  return {
@@ -456,6 +456,19 @@ describe('calendarSchema', () => {
456
456
  });
457
457
 
458
458
  describe('excepts', () => {
459
+ it('rejects an except with an empty name', () => {
460
+ const result = calendarSchema.safeParse({
461
+ ...minimalValidInput,
462
+ excepts: [
463
+ {
464
+ name: '',
465
+ },
466
+ ],
467
+ });
468
+
469
+ expect(result.success).toBe(false);
470
+ });
471
+
459
472
  it('accepts valid except objects', () => {
460
473
  const excepts = [
461
474
  {
@@ -155,8 +155,8 @@ export const getCalendarDayRangeIssues = (
155
155
  });
156
156
  };
157
157
 
158
- const exceptUiSchema = z.object({
159
- name: z.string().optional(),
158
+ export const calendarExceptSchema = z.object({
159
+ name: z.string().min(1),
160
160
  date: z
161
161
  .union([
162
162
  z.number(),
@@ -210,5 +210,5 @@ export const calendarSchema = z.object<
210
210
  expires: z.boolean().optional().default(false),
211
211
  accepts: acceptsOfDayUiArraySchema.default(defaultAccepts),
212
212
  specials: z.array(acceptOfDayUiSchema).default(defaultSpecials),
213
- excepts: z.array(exceptUiSchema).optional().default([]),
213
+ excepts: z.array(calendarExceptSchema).optional().default([]),
214
214
  });