import { LeadCreatedEvent } from '../events/lead-created.event';
import { LeadStatusChangedEvent } from '../events/lead-status-changed.event';

describe('LeadCreatedEvent', () => {
  it('stores the aggregate id and agent id', () => {
    const event = new LeadCreatedEvent('lead-1', 'agent-1');

    expect(event.aggregateId).toBe('lead-1');
    expect(event.agentId).toBe('agent-1');
  });

  it('has the correct event name', () => {
    const event = new LeadCreatedEvent('lead-1', 'agent-1');

    expect(event.eventName).toBe('lead.created');
  });

  it('records the occurred timestamp', () => {
    const before = new Date();
    const event = new LeadCreatedEvent('lead-1', 'agent-1');
    const after = new Date();

    expect(event.occurredAt.getTime()).toBeGreaterThanOrEqual(before.getTime());
    expect(event.occurredAt.getTime()).toBeLessThanOrEqual(after.getTime());
  });
});

describe('LeadStatusChangedEvent', () => {
  it('stores all properties correctly', () => {
    const event = new LeadStatusChangedEvent('lead-1', 'agent-1', 'NEW', 'CONTACTED');

    expect(event.aggregateId).toBe('lead-1');
    expect(event.agentId).toBe('agent-1');
    expect(event.oldStatus).toBe('NEW');
    expect(event.newStatus).toBe('CONTACTED');
  });

  it('has the correct event name', () => {
    const event = new LeadStatusChangedEvent('lead-1', 'agent-1', 'NEW', 'CONTACTED');

    expect(event.eventName).toBe('lead.status_changed');
  });

  it('records the occurred timestamp', () => {
    const before = new Date();
    const event = new LeadStatusChangedEvent('lead-1', 'agent-1', 'NEW', 'CONTACTED');
    const after = new Date();

    expect(event.occurredAt.getTime()).toBeGreaterThanOrEqual(before.getTime());
    expect(event.occurredAt.getTime()).toBeLessThanOrEqual(after.getTime());
  });

  it('captures different status transitions', () => {
    const event = new LeadStatusChangedEvent('lead-1', 'agent-1', 'QUALIFIED', 'NEGOTIATING');

    expect(event.oldStatus).toBe('QUALIFIED');
    expect(event.newStatus).toBe('NEGOTIATING');
  });
});
