import { InventoryMonitoringService } from './inventory-monitoring.service';
import type { InventoryMonitoringRepository } from './inventory-monitoring.repository';
import { inventoryServiceFixtures } from '@test-fixtures/monitoring/inventory/scenario.fixture';

describe('InventoryMonitoringService', () => {
  let service: InventoryMonitoringService;
  let repository: jest.Mocked<InventoryMonitoringRepository>;
  let findInventoryList: jest.Mock;

  beforeEach(() => {
    findInventoryList = jest.fn();
    repository = {
      findInventoryList,
    } as unknown as jest.Mocked<InventoryMonitoringRepository>;
    service = new InventoryMonitoringService(repository);
  });

  afterEach(() => {
    jest.clearAllMocks();
  });

  it('delegates to repository and transforms results', async () => {
    findInventoryList.mockResolvedValue(inventoryServiceFixtures.listRows);

    const result = await service.findInventoryList(
      inventoryServiceFixtures.query,
    );

    expect(findInventoryList).toHaveBeenCalledWith(
      inventoryServiceFixtures.repositoryQuery,
    );
    expect(result).toEqual(inventoryServiceFixtures.expectedResult);
  });
});
