core tests
This commit is contained in:
74
core/racing/domain/services/SeasonScheduleGenerator.test.ts
Normal file
74
core/racing/domain/services/SeasonScheduleGenerator.test.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { SeasonScheduleGenerator } from './SeasonScheduleGenerator';
|
||||
import { SeasonSchedule } from '../value-objects/SeasonSchedule';
|
||||
import { RecurrenceStrategy } from '../value-objects/RecurrenceStrategy';
|
||||
import { RaceTimeOfDay } from '../value-objects/RaceTimeOfDay';
|
||||
import { WeekdaySet } from '../value-objects/WeekdaySet';
|
||||
import { LeagueTimezone } from '../value-objects/LeagueTimezone';
|
||||
import { MonthlyRecurrencePattern } from '../value-objects/MonthlyRecurrencePattern';
|
||||
|
||||
describe('SeasonScheduleGenerator', () => {
|
||||
it('should generate weekly slots', () => {
|
||||
const startDate = new Date(2024, 0, 1); // Monday, Jan 1st 2024
|
||||
const schedule = new SeasonSchedule({
|
||||
startDate,
|
||||
plannedRounds: 4,
|
||||
timeOfDay: new RaceTimeOfDay(20, 0),
|
||||
timezone: LeagueTimezone.create('UTC'),
|
||||
recurrence: RecurrenceStrategy.weekly(WeekdaySet.fromArray(['Mon'])),
|
||||
});
|
||||
|
||||
const slots = SeasonScheduleGenerator.generateSlots(schedule);
|
||||
|
||||
expect(slots).toHaveLength(4);
|
||||
expect(slots[0].roundNumber).toBe(1);
|
||||
expect(slots[0].scheduledAt.getHours()).toBe(20);
|
||||
expect(slots[0].scheduledAt.getMinutes()).toBe(0);
|
||||
expect(slots[0].scheduledAt.getFullYear()).toBe(2024);
|
||||
expect(slots[0].scheduledAt.getMonth()).toBe(0);
|
||||
expect(slots[0].scheduledAt.getDate()).toBe(1);
|
||||
|
||||
expect(slots[1].roundNumber).toBe(2);
|
||||
expect(slots[1].scheduledAt.getDate()).toBe(8);
|
||||
expect(slots[2].roundNumber).toBe(3);
|
||||
expect(slots[2].scheduledAt.getDate()).toBe(15);
|
||||
expect(slots[3].roundNumber).toBe(4);
|
||||
expect(slots[3].scheduledAt.getDate()).toBe(22);
|
||||
});
|
||||
|
||||
it('should generate slots every 2 weeks', () => {
|
||||
const startDate = new Date(2024, 0, 1);
|
||||
const schedule = new SeasonSchedule({
|
||||
startDate,
|
||||
plannedRounds: 2,
|
||||
timeOfDay: new RaceTimeOfDay(20, 0),
|
||||
timezone: LeagueTimezone.create('UTC'),
|
||||
recurrence: RecurrenceStrategy.everyNWeeks(2, WeekdaySet.fromArray(['Mon'])),
|
||||
});
|
||||
|
||||
const slots = SeasonScheduleGenerator.generateSlots(schedule);
|
||||
|
||||
expect(slots).toHaveLength(2);
|
||||
expect(slots[0].scheduledAt.getDate()).toBe(1);
|
||||
expect(slots[1].scheduledAt.getDate()).toBe(15);
|
||||
});
|
||||
|
||||
it('should generate monthly slots (nth weekday)', () => {
|
||||
const startDate = new Date(2024, 0, 1);
|
||||
const schedule = new SeasonSchedule({
|
||||
startDate,
|
||||
plannedRounds: 2,
|
||||
timeOfDay: new RaceTimeOfDay(20, 0),
|
||||
timezone: LeagueTimezone.create('UTC'),
|
||||
recurrence: RecurrenceStrategy.monthlyNthWeekday(MonthlyRecurrencePattern.create(1, 'Mon')),
|
||||
});
|
||||
|
||||
const slots = SeasonScheduleGenerator.generateSlots(schedule);
|
||||
|
||||
expect(slots).toHaveLength(2);
|
||||
expect(slots[0].scheduledAt.getMonth()).toBe(0);
|
||||
expect(slots[0].scheduledAt.getDate()).toBe(1);
|
||||
expect(slots[1].scheduledAt.getMonth()).toBe(1);
|
||||
expect(slots[1].scheduledAt.getDate()).toBe(5);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user