import { describe, it, expect } from 'vitest';
import { ListingApprovedEvent } from '../events/listing-approved.event';
import { ListingCreatedEvent } from '../events/listing-created.event';
import { ListingSoldEvent } from '../events/listing-sold.event';

describe('Listings Domain Events', () => {
  describe('ListingCreatedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new ListingCreatedEvent('listing-1', 'prop-1', 'seller-1', 'SALE');

      expect(event.eventName).toBe('listing.created');
      expect(event.aggregateId).toBe('listing-1');
      expect(event.propertyId).toBe('prop-1');
      expect(event.sellerId).toBe('seller-1');
      expect(event.transactionType).toBe('SALE');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });

    it('creates event for RENT transaction', () => {
      const event = new ListingCreatedEvent('listing-2', 'prop-2', 'seller-2', 'RENT');
      expect(event.transactionType).toBe('RENT');
    });
  });

  describe('ListingApprovedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new ListingApprovedEvent('listing-1', 'prop-1');

      expect(event.eventName).toBe('listing.approved');
      expect(event.aggregateId).toBe('listing-1');
      expect(event.propertyId).toBe('prop-1');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('ListingSoldEvent', () => {
    it('creates event with SOLD status', () => {
      const event = new ListingSoldEvent('listing-1', 'prop-1', 'SOLD');

      expect(event.eventName).toBe('listing.sold');
      expect(event.aggregateId).toBe('listing-1');
      expect(event.propertyId).toBe('prop-1');
      expect(event.finalStatus).toBe('SOLD');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });

    it('creates event with RENTED status', () => {
      const event = new ListingSoldEvent('listing-2', 'prop-2', 'RENTED');
      expect(event.finalStatus).toBe('RENTED');
    });
  });
});
