|
| 1 | +import { scheduleSchema } from '../schedule.js'; |
| 2 | + |
| 3 | +describe('scheduleSchema', () => { |
| 4 | + it('should default day_of_week, time, and until to null when omitted', () => { |
| 5 | + const result = scheduleSchema.parse({ |
| 6 | + interval: 86400, |
| 7 | + }); |
| 8 | + expect(result).toEqual({ |
| 9 | + interval: 86400, |
| 10 | + time: null, |
| 11 | + until: null, |
| 12 | + day_of_week: null, |
| 13 | + }); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should preserve day_of_week when explicitly provided', () => { |
| 17 | + const result = scheduleSchema.parse({ |
| 18 | + interval: 604800, |
| 19 | + time: '06:00', |
| 20 | + day_of_week: 'Monday', |
| 21 | + }); |
| 22 | + expect(result).toMatchObject({ |
| 23 | + interval: 604800, |
| 24 | + day_of_week: 'Monday', |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should accept all valid day_of_week values', () => { |
| 29 | + const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; |
| 30 | + for (const day of days) { |
| 31 | + const result = scheduleSchema.parse({ interval: 604800, day_of_week: day }); |
| 32 | + expect(result).toMatchObject({ day_of_week: day }); |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + it('should reject invalid day_of_week string', () => { |
| 37 | + expect(() => scheduleSchema.parse({ |
| 38 | + interval: 604800, |
| 39 | + day_of_week: 'monday', |
| 40 | + })).toThrow(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should preserve day_of_week as null when explicitly set to null', () => { |
| 44 | + const result = scheduleSchema.parse({ |
| 45 | + interval: 86400, |
| 46 | + day_of_week: null, |
| 47 | + }); |
| 48 | + expect(result).toMatchObject({ |
| 49 | + interval: 86400, |
| 50 | + day_of_week: null, |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should preserve time and until when provided', () => { |
| 55 | + const result = scheduleSchema.parse({ |
| 56 | + interval: 86400, |
| 57 | + time: '01:15', |
| 58 | + until: '2026-08-14', |
| 59 | + }); |
| 60 | + expect(result).toEqual({ |
| 61 | + interval: 86400, |
| 62 | + time: '01:15', |
| 63 | + until: '2026-08-14', |
| 64 | + day_of_week: null, |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should return null for null input', () => { |
| 69 | + const result = scheduleSchema.parse(null); |
| 70 | + expect(result).toBeNull(); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should return undefined for undefined input', () => { |
| 74 | + const result = scheduleSchema.parse(undefined); |
| 75 | + expect(result).toBeUndefined(); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should accept disabled field', () => { |
| 79 | + const result = scheduleSchema.parse({ |
| 80 | + interval: 86400, |
| 81 | + disabled: true, |
| 82 | + }); |
| 83 | + expect(result).toMatchObject({ |
| 84 | + interval: 86400, |
| 85 | + day_of_week: null, |
| 86 | + disabled: true, |
| 87 | + }); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should reject invalid interval type', () => { |
| 91 | + expect(() => scheduleSchema.parse({ |
| 92 | + interval: 'daily', |
| 93 | + })).toThrow(); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should require interval', () => { |
| 97 | + expect(() => scheduleSchema.parse({ |
| 98 | + time: '01:15', |
| 99 | + })).toThrow(); |
| 100 | + }); |
| 101 | +}); |
0 commit comments