import { TrackEventCommand } from '../commands/track-event/track-event.command';
import { TrackEventHandler } from '../commands/track-event/track-event.handler';

describe('TrackEventHandler', () => {
  let handler: TrackEventHandler;

  beforeEach(() => {
    const mockLogger = { log: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn(), verbose: vi.fn() };
    handler = new TrackEventHandler(mockLogger as any);
  });

  it('tracks an event and returns result', async () => {
    const command = new TrackEventCommand(
      'page_view',
      'listing-123',
      'LISTING',
      { source: 'search' },
      'user-1',
    );

    const result = await handler.execute(command);

    expect(result.tracked).toBe(true);
    expect(result.eventType).toBe('page_view');
  });

  it('tracks event without userId', async () => {
    const command = new TrackEventCommand(
      'search',
      'query-abc',
      'SEARCH',
      { keyword: 'Quận 7' },
    );

    const result = await handler.execute(command);

    expect(result.tracked).toBe(true);
    expect(result.eventType).toBe('search');
  });
});
