import { isObject, parseBoolean, select, toSnakeCase } from './index';

describe('toSnakeCase function', function () {
  it('transforms to snake case', function () {
    const test = 'lorem ipsum sit amet';
    const result = toSnakeCase(test);

    expect(result).toBe('lorem_ipsum_sit_amet');
  });

  it('transforms return empty string if parameter is not a string', function () {
    const result = toSnakeCase(1 as any);
    expect(result).toBe('');
  });
});

describe('isObject function', function () {
  it('returns true when is an object', function () {
    const test = {
      test: 'test',
    };
    const result = isObject(test);

    expect(result).toBeTruthy();
  });

  it('returns false when is not an object', function () {
    const test = 'test';
    const result = isObject(test);

    expect(result).toBeFalsy();
  });

  it('returns false when is null', function () {
    const test = null;
    const result = isObject(test);

    expect(result).toBeFalsy();
  });

  it('returns false when is undefined', function () {
    const test = undefined;
    const result = isObject(test);

    expect(result).toBeFalsy();
  });
});

describe('parseBoolean function', function () {
  it('returns "true" when input string is "1"', function () {
    const shouldBeTrue = parseBoolean('1');

    expect(shouldBeTrue).toBeTruthy();
  });

  it('returns "true" when input string is "True"', function () {
    const shouldBeTrue = parseBoolean('True');

    expect(shouldBeTrue).toBeTruthy();
  });

  it('returns "true" when input string is "true"', function () {
    const shouldBeTrue = parseBoolean('true');

    expect(shouldBeTrue).toBeTruthy();
  });

  it('returns "false" when input string is "false', function () {
    const shouldBeFalse = parseBoolean('false');

    expect(shouldBeFalse).toBeFalsy();
  });
});

describe('select function', function () {
  it('return the condition value', function () {
    const result = select({ a: 'good', b: 'better', default: 'bad' }, 'a');
    expect(result).toBe('good');
  });

  it('return the condition value when value is empty string', function () {
    const result = select({ a: '', b: '', default: 'bad' }, 'a');
    expect(result).toBe('');
  });

  it('return the default value', function () {
    const result = select({ a: 'good', b: 'better', default: 'bad' }, 'c');
    expect(result).toBe('bad');
  });
});
