import { hasAnyErrors } from './utils';

// Helper: minimal error group structure
const emptyErrorGroup = { ANDROID: [], IOS: [], GENERIC: [] };
const errorInAndroid = { ANDROID: ['Some error'], IOS: [], GENERIC: [] };
const errorInIOS = { ANDROID: [], IOS: ['Some error'], GENERIC: [] };
const errorInGeneric = { ANDROID: [], IOS: [], GENERIC: ['Some error'] };


describe('hasAnyErrors', () => {
  it('returns false if errorMessage is null', () => {
    expect(hasAnyErrors(null)).toBe(false);
  });

  it('returns false if errorMessage is undefined', () => {
    expect(hasAnyErrors(undefined)).toBe(false);
  });

  it('returns false if both STANDARD_ERROR_MSG and LIQUID_ERROR_MSG are missing', () => {
    expect(hasAnyErrors({})).toBe(false);
  });

  it('returns false if both STANDARD_ERROR_MSG and LIQUID_ERROR_MSG are empty', () => {
    const errorMessage = {
      STANDARD_ERROR_MSG: emptyErrorGroup,
      LIQUID_ERROR_MSG: emptyErrorGroup,
    };
    expect(hasAnyErrors(errorMessage)).toBe(false);
  });

  it('returns true if STANDARD_ERROR_MSG has errors', () => {
    const errorMessage = {
      STANDARD_ERROR_MSG: errorInAndroid,
      LIQUID_ERROR_MSG: emptyErrorGroup,
    };
    expect(hasAnyErrors(errorMessage)).toBe(true);
  });

  it('returns true if LIQUID_ERROR_MSG has errors', () => {
    const errorMessage = {
      STANDARD_ERROR_MSG: emptyErrorGroup,
      LIQUID_ERROR_MSG: errorInIOS,
    };
    expect(hasAnyErrors(errorMessage)).toBe(true);
  });

  it('returns true if both STANDARD_ERROR_MSG and LIQUID_ERROR_MSG have errors', () => {
    const errorMessage = {
      STANDARD_ERROR_MSG: errorInGeneric,
      LIQUID_ERROR_MSG: errorInAndroid,
    };
    expect(hasAnyErrors(errorMessage)).toBe(true);
  });

  it('returns false if error groups are present but all arrays are empty', () => {
    const errorMessage = {
      STANDARD_ERROR_MSG: { ANDROID: [], IOS: [], GENERIC: [] },
      LIQUID_ERROR_MSG: { ANDROID: [], IOS: [], GENERIC: [] },
    };
    expect(hasAnyErrors(errorMessage)).toBe(false);
  });

  it('returns false if error groups are missing all platforms', () => {
    const errorMessage = {
      STANDARD_ERROR_MSG: {},
      LIQUID_ERROR_MSG: {},
    };
    expect(hasAnyErrors(errorMessage)).toBe(false);
  });
}); 