import { InquiryCreatedEvent } from '../events/inquiry-created.event';
import { InquiryReadEvent } from '../events/inquiry-read.event';

describe('InquiryCreatedEvent', () => {
  it('stores the aggregate id, listing id, and user id', () => {
    const event = new InquiryCreatedEvent('inq-1', 'listing-1', 'user-1');

    expect(event.aggregateId).toBe('inq-1');
    expect(event.listingId).toBe('listing-1');
    expect(event.userId).toBe('user-1');
  });

  it('has the correct event name', () => {
    const event = new InquiryCreatedEvent('inq-1', 'listing-1', 'user-1');

    expect(event.eventName).toBe('inquiry.received');
  });

  it('records the occurred timestamp', () => {
    const before = new Date();
    const event = new InquiryCreatedEvent('inq-1', 'listing-1', 'user-1');
    const after = new Date();

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

describe('InquiryReadEvent', () => {
  it('stores the aggregate id, listing id, and user id', () => {
    const event = new InquiryReadEvent('inq-1', 'listing-1', 'user-1');

    expect(event.aggregateId).toBe('inq-1');
    expect(event.listingId).toBe('listing-1');
    expect(event.userId).toBe('user-1');
  });

  it('has the correct event name', () => {
    const event = new InquiryReadEvent('inq-1', 'listing-1', 'user-1');

    expect(event.eventName).toBe('inquiry.read');
  });

  it('records the occurred timestamp', () => {
    const before = new Date();
    const event = new InquiryReadEvent('inq-1', 'listing-1', 'user-1');
    const after = new Date();

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