import { checkForNullOrUndefined, isNullOrUndefined, equalsIgnoreCase } from '../../src/functions/data.helper.js'; 

describe('Utility Functions', () => {

  describe('checkForNullOrUndefined', () => {
    it('should throw an error when the input is null', () => {
      expect(() => checkForNullOrUndefined(null, 'Input cannot be null')).toThrow('Input cannot be null');
    });

    it('should throw an error when the input is undefined', () => {
      expect(() => checkForNullOrUndefined(undefined, 'Input cannot be undefined')).toThrow('Input cannot be undefined');
    });

    it('should return the input when it is not null or undefined', () => {
      const input = 'valid input';
      expect(checkForNullOrUndefined(input, 'Input cannot be null or undefined')).toBe(input);
    });

    it('should work with numbers', () => {
      const input = 42;
      expect(checkForNullOrUndefined(input, 'Number cannot be null or undefined')).toBe(input);
    });

    it('should work with objects', () => {
      const input = { key: 'value' };
      expect(checkForNullOrUndefined(input, 'Object cannot be null or undefined')).toBe(input);
    });
  });

  // Tests for isNullOrUndefined
  describe('isNullOrUndefined', () => {
    it('should return true when the input is null', () => {
      expect(isNullOrUndefined(null)).toBe(true);
    });

    it('should return true when the input is undefined', () => {
      expect(isNullOrUndefined(undefined)).toBe(true);
    });

    it('should return false when the input is not null or undefined', () => {
      expect(isNullOrUndefined('valid input')).toBe(false);
      expect(isNullOrUndefined(42)).toBe(false);
      expect(isNullOrUndefined({ key: 'value' })).toBe(false);
    });
  });

  
  describe('equalsIgnoreCase', () => {

    it('should return true for strings that are equal ignoring case', () => {
      expect(equalsIgnoreCase('TEST', 'test')).toBe(true);
      expect(equalsIgnoreCase('Test', 'test')).toBe(true);
    });

    it('should return false for strings that are not equal ignoring case', () => {
      expect(equalsIgnoreCase('TEST', 'different')).toBe(false);
      expect(equalsIgnoreCase('Test', 'other')).toBe(false);
    });

    it('should handle mixed inputs with numbers and strings', () => {
      expect(equalsIgnoreCase('123', '123')).toBe(true);
      expect(equalsIgnoreCase('123', '456')).toBe(false);
    });
  });
});
