import { describe, it, expect } from 'vitest';
import { hasLoyaltyCollectCommand } from './has-loyalty-collect-command.helper';
import { DisplayOrderItemSubset } from '@isa/oms/data-access';

describe('hasLoyaltyCollectCommand', () => {
  describe('when items is undefined', () => {
    it('should return false', () => {
      // Act
      const result = hasLoyaltyCollectCommand(undefined);

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

  describe('when items is empty array', () => {
    it('should return false', () => {
      // Arrange
      const items: DisplayOrderItemSubset[] = [];

      // Act
      const result = hasLoyaltyCollectCommand(items);

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

  describe('when items have no actions', () => {
    it('should return false', () => {
      // Arrange
      const items: DisplayOrderItemSubset[] = [
        {
          id: 1,
          quantity: 1,
        } as DisplayOrderItemSubset,
      ];

      // Act
      const result = hasLoyaltyCollectCommand(items);

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

  describe('when items have actions but no LOYALTY_COLLECT_COMMAND', () => {
    it('should return false', () => {
      // Arrange
      const items: any[] = [
        {
          id: 1,
          quantity: 1,
          actions: [
            { command: 'SOME_OTHER_COMMAND', label: 'Other Action' },
            { command: 'ANOTHER_COMMAND', label: 'Another Action' },
          ],
        },
      ];

      // Act
      const result = hasLoyaltyCollectCommand(items);

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

  describe('when items have LOYALTY_COLLECT_COMMAND action', () => {
    it('should return true', () => {
      // Arrange
      const items: any[] = [
        {
          id: 1,
          quantity: 1,
          actions: [
            {
              command: 'LOYALTY_COLLECT_COMMAND',
              label: 'Abschließen',
              selected: true,
              value: 'Abschließen',
            },
          ],
        },
      ];

      // Act
      const result = hasLoyaltyCollectCommand(items);

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

  describe('when items have multiple actions including LOYALTY_COLLECT_COMMAND', () => {
    it('should return true', () => {
      // Arrange
      const items: any[] = [
        {
          id: 1,
          quantity: 1,
          actions: [
            { command: 'SOME_OTHER_COMMAND', label: 'Other Action' },
            {
              command: 'LOYALTY_COLLECT_COMMAND',
              label: 'Abschließen',
              selected: true,
              value: 'Abschließen',
            },
            { command: 'ANOTHER_COMMAND', label: 'Another Action' },
          ],
        },
      ];

      // Act
      const result = hasLoyaltyCollectCommand(items);

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