import { getReceiptStatusFromReturn } from './get-receipt-status-from-return.helper';
import { ReceiptCompleteStatus, Return } from '../models';

describe('getReceiptStatusFromReturn', () => {
  it('should return Offen when no receipts exist', () => {
    // Arrange
    const returnData: Return = {
      receipts: [] as any,
    } as Return;

    // Act
    const result = getReceiptStatusFromReturn(returnData);

    // Assert
    expect(result).toBe(ReceiptCompleteStatus.Offen);
  });

  it('should return Offen when receipts array is undefined', () => {
    // Arrange
    const returnData: Return = {} as Return;

    // Act
    const result = getReceiptStatusFromReturn(returnData);

    // Assert
    expect(result).toBe(ReceiptCompleteStatus.Offen);
  });

  it('should return Abgeschlossen when at least one receipt is completed', () => {
    // Arrange
    const returnData: Return = {
      receipts: [
        { data: { completed: 'Offen' } },
        { data: { completed: 'Abgeschlossen' } },
      ],
    } as Return;

    // Act
    const result = getReceiptStatusFromReturn(returnData);

    // Assert
    expect(result).toBe(ReceiptCompleteStatus.Abgeschlossen);
  });

  it('should return Abgeschlossen when all receipts are incomplete', () => {
    // Arrange
    const returnData: Return = {
      receipts: [
        { data: { completed: 'Abgeschlossen' } },
        { data: { completed: 'Abgeschlossen' } },
      ],
    } as Return;

    // Act
    const result = getReceiptStatusFromReturn(returnData);

    // Assert
    expect(result).toBe(ReceiptCompleteStatus.Abgeschlossen);
  });

  it('should return Offen when receipt data is undefined', () => {
    // Arrange
    const returnData: Return = {
      receipts: [{ data: undefined }, {}],
    } as Return;

    // Act
    const result = getReceiptStatusFromReturn(returnData);

    // Assert
    expect(result).toBe(ReceiptCompleteStatus.Offen);
  });
});
