import { SyncListingCommand } from '../commands/sync-listing/sync-listing.command';
import { SyncListingHandler } from '../commands/sync-listing/sync-listing.handler';

describe('SyncListingHandler', () => {
  let handler: SyncListingHandler;
  let mockIndexer: { reindexAll: ReturnType<typeof vi.fn>; indexListing: ReturnType<typeof vi.fn>; removeListing: ReturnType<typeof vi.fn> };

  beforeEach(() => {
    mockIndexer = {
      reindexAll: vi.fn(),
      indexListing: vi.fn(),
      removeListing: vi.fn(),
    };
    handler = new SyncListingHandler(mockIndexer as any);
  });

  it('indexes a listing by id', async () => {
    mockIndexer.indexListing.mockResolvedValue(undefined);

    const command = new SyncListingCommand('listing-123');
    await handler.execute(command);

    expect(mockIndexer.indexListing).toHaveBeenCalledWith('listing-123');
    expect(mockIndexer.indexListing).toHaveBeenCalledTimes(1);
  });
});
