import { pick } from './pick';

describe('pick', () => {
  it('should pick properties from the 1st level from the object', () => {
    const obj = {
      foo: 'bar',
    };
    expect(pick('foo', obj)).toEqual('bar');
  });

  it('should pick properties from the 2nd level from the object', () => {
    const obj = {
      foo: {
        bar: 'baz',
      },
    };
    expect(pick('foo.bar', obj)).toEqual('baz');
  });

  it('should pick properties from the 3rd level from the object', () => {
    const obj = {
      foo: {
        bar: {
          baz: 'qux',
        },
      },
    };
    expect(pick('foo.bar.baz', obj)).toEqual('qux');
  });

  it('should throw an error of obj is not an object', () => {
    expect(() => pick('foo', 'bar')).toThrowError(`bar is not an object`);
  });

  it('should return undefined if the property is not found', () => {
    const obj = {
      foo: 'bar',
    };
    expect(pick('bar', obj)).toEqual(undefined);
  });
});
