import { calculateTargetStock } from './calc-target-stock.helper';

describe('calculateTargetStock', () => {
  it('should return remainingQuantityInStock if set', () => {
    // Arrange
    const input = {
      availableStock: 10,
      stockToRemit: 3,
      remainingQuantityInStock: 5,
    };

    // Act
    const result = calculateTargetStock(input);

    // Assert
    expect(result).toBe(5);
  });

  it('should calculate as availableStock - stockToRemit if remainingQuantityInStock is not set', () => {
    // Arrange
    const input = {
      availableStock: 10,
      stockToRemit: 4,
    };

    // Act
    const result = calculateTargetStock(input);

    // Assert
    expect(result).toBe(6);
  });

  it('should return 0 if result is negative', () => {
    // Arrange
    const input = {
      availableStock: 2,
      stockToRemit: 5,
    };

    // Act
    const result = calculateTargetStock(input);

    // Assert
    expect(result).toBe(0);
  });

  it('should treat undefined stockToRemit as 0', () => {
    // Arrange
    const input = {
      availableStock: 7,
    };

    // Act
    const result = calculateTargetStock(input);

    // Assert
    expect(result).toBe(7);
  });
});
