import { describe, it, expect } from 'vitest';
import { AgentVerifiedEvent } from '../events/agent-verified.event';
import { UserDeactivatedEvent } from '../events/user-deactivated.event';
import { UserKycUpdatedEvent } from '../events/user-kyc-updated.event';
import { UserRegisteredEvent } from '../events/user-registered.event';

describe('Auth Domain Events', () => {
  describe('UserRegisteredEvent', () => {
    it('creates event with correct properties', () => {
      const event = new UserRegisteredEvent('user-1', '+84912345678', 'BUYER');

      expect(event.eventName).toBe('user.registered');
      expect(event.aggregateId).toBe('user-1');
      expect(event.phone).toBe('+84912345678');
      expect(event.role).toBe('BUYER');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });

    it('creates event for AGENT role', () => {
      const event = new UserRegisteredEvent('user-2', '+84987654321', 'AGENT');
      expect(event.role).toBe('AGENT');
    });

    it('creates event for SELLER role', () => {
      const event = new UserRegisteredEvent('user-3', '+84955555555', 'SELLER');
      expect(event.role).toBe('SELLER');
    });
  });

  describe('AgentVerifiedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new AgentVerifiedEvent('agent-1', 'user-1');

      expect(event.eventName).toBe('agent.verified');
      expect(event.aggregateId).toBe('agent-1');
      expect(event.userId).toBe('user-1');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('UserKycUpdatedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new UserKycUpdatedEvent('user-1', 'APPROVED', 'PENDING');

      expect(event.eventName).toBe('user.kyc_updated');
      expect(event.aggregateId).toBe('user-1');
      expect(event.newStatus).toBe('APPROVED');
      expect(event.previousStatus).toBe('PENDING');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });

    it('creates event for rejection', () => {
      const event = new UserKycUpdatedEvent('user-2', 'REJECTED', 'PENDING');
      expect(event.newStatus).toBe('REJECTED');
      expect(event.previousStatus).toBe('PENDING');
    });
  });

  describe('UserDeactivatedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new UserDeactivatedEvent('user-1');

      expect(event.eventName).toBe('user.deactivated');
      expect(event.aggregateId).toBe('user-1');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });
});
