import { describe, expect, it } from 'vitest'; import { LeagueTimezone } from './LeagueTimezone'; import { ScheduledRaceSlot } from './ScheduledRaceSlot'; describe('ScheduledRaceSlot', () => { it('should create scheduled race slot', () => { const timezone = LeagueTimezone.create('America/New_York'); const scheduledAt = new Date('2023-10-01T12:00:00Z'); const slot = new ScheduledRaceSlot({ roundNumber: 1, scheduledAt, timezone, }); expect(slot.roundNumber).toBe(1); expect(slot.scheduledAt).toBe(scheduledAt); expect(slot.timezone).toBe(timezone); }); it('should throw if roundNumber not positive integer', () => { const timezone = LeagueTimezone.create('UTC'); const scheduledAt = new Date(); expect(() => new ScheduledRaceSlot({ roundNumber: 0, scheduledAt, timezone })).toThrow('ScheduledRaceSlot.roundNumber must be a positive integer'); expect(() => new ScheduledRaceSlot({ roundNumber: -1, scheduledAt, timezone })).toThrow('ScheduledRaceSlot.roundNumber must be a positive integer'); expect(() => new ScheduledRaceSlot({ roundNumber: 1.5, scheduledAt, timezone })).toThrow('ScheduledRaceSlot.roundNumber must be a positive integer'); }); it('should throw if scheduledAt not valid Date', () => { const timezone = LeagueTimezone.create('UTC'); expect(() => new ScheduledRaceSlot({ roundNumber: 1, scheduledAt: new Date('invalid'), timezone })).toThrow('ScheduledRaceSlot.scheduledAt must be a valid Date'); }); it('should equal same slots', () => { const timezone1 = LeagueTimezone.create('Europe/London'); const timezone2 = LeagueTimezone.create('Europe/London'); const date1 = new Date('2023-05-15T10:00:00Z'); const date2 = new Date('2023-05-15T10:00:00Z'); const s1 = new ScheduledRaceSlot({ roundNumber: 2, scheduledAt: date1, timezone: timezone1 }); const s2 = new ScheduledRaceSlot({ roundNumber: 2, scheduledAt: date2, timezone: timezone2 }); expect(s1.equals(s2)).toBe(true); }); it('should not equal different round numbers', () => { const timezone = LeagueTimezone.create('UTC'); const date = new Date(); const s1 = new ScheduledRaceSlot({ roundNumber: 1, scheduledAt: date, timezone }); const s2 = new ScheduledRaceSlot({ roundNumber: 2, scheduledAt: date, timezone }); expect(s1.equals(s2)).toBe(false); }); it('should not equal different dates', () => { const timezone = LeagueTimezone.create('UTC'); const s1 = new ScheduledRaceSlot({ roundNumber: 1, scheduledAt: new Date('2023-01-01'), timezone }); const s2 = new ScheduledRaceSlot({ roundNumber: 1, scheduledAt: new Date('2023-01-02'), timezone }); expect(s1.equals(s2)).toBe(false); }); it('should not equal different timezones', () => { const timezone1 = LeagueTimezone.create('UTC'); const timezone2 = LeagueTimezone.create('EST'); const date = new Date(); const s1 = new ScheduledRaceSlot({ roundNumber: 1, scheduledAt: date, timezone: timezone1 }); const s2 = new ScheduledRaceSlot({ roundNumber: 1, scheduledAt: date, timezone: timezone2 }); expect(s1.equals(s2)).toBe(false); }); });