import { RegisteredAt } from './RegisteredAt';
import { RacingDomainValidationError } from '../errors/RacingDomainError';

describe('RegisteredAt', () => {
  describe('create', () => {
    it('should create a RegisteredAt with a valid date', () => {
      const date = new Date('2023-01-01T00:00:00Z');
      const registeredAt = RegisteredAt.create(date);
      expect(registeredAt.toDate()).toEqual(date);
    });

    it('should throw an error for invalid date', () => {
      expect(() => RegisteredAt.create(new Date('invalid'))).toThrow(RacingDomainValidationError);
    });
  });

  describe('toDate', () => {
    it('should return a copy of the date', () => {
      const date = new Date();
      const registeredAt = RegisteredAt.create(date);
      const result = registeredAt.toDate();
      expect(result).toEqual(date);
      expect(result).not.toBe(date); // should be a copy
    });
  });

  describe('equals', () => {
    it('should return true for equal dates', () => {
      const date1 = new Date('2023-01-01T00:00:00Z');
      const date2 = new Date('2023-01-01T00:00:00Z');
      const registeredAt1 = RegisteredAt.create(date1);
      const registeredAt2 = RegisteredAt.create(date2);
      expect(registeredAt1.equals(registeredAt2)).toBe(true);
    });

    it('should return false for different dates', () => {
      const date1 = new Date('2023-01-01T00:00:00Z');
      const date2 = new Date('2023-01-02T00:00:00Z');
      const registeredAt1 = RegisteredAt.create(date1);
      const registeredAt2 = RegisteredAt.create(date2);
      expect(registeredAt1.equals(registeredAt2)).toBe(false);
    });
  });
});