import { Month } from './month.vo' import { DomainError } from '@/shared/exceptions' describe('Month Value Object', () => { describe('create', () => { it('should create a valid month', () => { const month = Month.create('2024-01') expect(month.value).toBe('2024-01') }) it('should throw error for invalid format', () => { expect(() => Month.create('2024-1')).toThrow(DomainError) expect(() => Month.create('2024/01')).toThrow(DomainError) expect(() => Month.create('202401')).toThrow(DomainError) expect(() => Month.create('invalid')).toThrow(DomainError) }) }) describe('current', () => { it('should return current month in YYYY-MM format', () => { const month = Month.current() expect(month.value).toMatch(/^\d{4}-\d{2}$/) }) }) describe('next', () => { it('should return next month', () => { const month = Month.create('2024-01') expect(month.next().value).toBe('2024-02') }) it('should handle year transition', () => { const month = Month.create('2024-12') expect(month.next().value).toBe('2025-01') }) }) describe('previous', () => { it('should return previous month', () => { const month = Month.create('2024-02') expect(month.previous().value).toBe('2024-01') }) it('should handle year transition', () => { const month = Month.create('2024-01') expect(month.previous().value).toBe('2023-12') }) }) describe('equals', () => { it('should return true for equal months', () => { const month1 = Month.create('2024-01') const month2 = Month.create('2024-01') expect(month1.equals(month2)).toBe(true) }) it('should return false for different months', () => { const month1 = Month.create('2024-01') const month2 = Month.create('2024-02') expect(month1.equals(month2)).toBe(false) }) }) describe('isAfter/isBefore', () => { it('should compare months correctly', () => { const jan = Month.create('2024-01') const feb = Month.create('2024-02') expect(feb.isAfter(jan)).toBe(true) expect(jan.isBefore(feb)).toBe(true) expect(jan.isAfter(feb)).toBe(false) expect(feb.isBefore(jan)).toBe(false) }) }) describe('getYear/getMonth', () => { it('should extract year and month correctly', () => { const month = Month.create('2024-06') expect(month.getYear()).toBe(2024) expect(month.getMonth()).toBe(6) }) }) })