38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { CalendarRange } from './calendar-range.vo.js';
|
|
import { InvalidCalendarRangeException } from '../exceptions/invalid-calendar-range.exception.js';
|
|
|
|
describe('CalendarRange', () => {
|
|
it('accepts a 6-week month grid', () => {
|
|
const from = new Date('2026-09-28T00:00:00+03:00');
|
|
const to = new Date('2026-11-09T00:00:00+03:00');
|
|
|
|
const range = CalendarRange.create({ from, to });
|
|
|
|
expect(range.from).toBe(from);
|
|
expect(range.to).toBe(to);
|
|
});
|
|
|
|
it('rejects an invalid date', () => {
|
|
expect(() => CalendarRange.create({ from: new Date('nope'), to: new Date() })).toThrow(
|
|
InvalidCalendarRangeException,
|
|
);
|
|
});
|
|
|
|
it('rejects from equal to or after to', () => {
|
|
const date = new Date('2026-10-01T00:00:00Z');
|
|
|
|
expect(() => CalendarRange.create({ from: date, to: date })).toThrow(InvalidCalendarRangeException);
|
|
expect(() => CalendarRange.create({ from: new Date('2026-10-02T00:00:00Z'), to: date })).toThrow(
|
|
InvalidCalendarRangeException,
|
|
);
|
|
});
|
|
|
|
it(`rejects a range longer than ${CalendarRange.MAX_DAYS} days`, () => {
|
|
const from = new Date('2026-10-01T00:00:00Z');
|
|
const to = new Date(from.getTime() + (CalendarRange.MAX_DAYS * 24 * 60 * 60 * 1000 + 1));
|
|
|
|
expect(() => CalendarRange.create({ from, to })).toThrow(InvalidCalendarRangeException);
|
|
});
|
|
});
|