import R from 'ramda';
import { expect } from 'chai'; // eslint-disable-line
import lib from './query-parser';

const query = {
  filter: {
    name: 'foo',
    tags: 'foo,bar,baz',
    empty: '',
    array: ['foo', 'bar'],
    lt: {
      lt: 20,
    },
    lte: {
      lte: 20,
    },
    gt: {
      gt: 20,
    },
    gte: {
      gte: 20,
    },
    contains: {
      contains: 'hello',
    },
  },
};

const takeFromQuery = path =>
  R.assocPath(path, R.path(path, query), {});

describe.only('lib/query-parser', () => {
  describe('filter', () => {
    describe('filter[name]=foo', () => {
      it('returns filter[Object(name in foo)]', () => {
        const q = takeFromQuery(['filter', 'name']);
        const expected = {
          column: 'name',
          operator: 'in',
          value: 'foo',
        };
        const r = lib(q);

        expect(r).to.have.property('filter').that.is.an('array');
        expect(r).to.have.property('filter').that.length(1);
        expect(r).to.have.property('filter').that.include(expected);
      });
    });

    describe('filter[tag]=foo,bar,baz', () => {
      it('returns filter[Object(tags in [foo, bar, baz])]', () => {
        const q = takeFromQuery(['filter', 'tags']);
        const expected = {
          column: 'tags',
          operator: 'in',
          value: ['foo', 'bar', 'baz'],
        };
        const r = lib(q);

        expect(r).to.have.property('filter').that.is.an('array');
        expect(r).to.have.property('filter').that.length(1);
        expect(r).to.have.property('filter').that.include(expected);
      });
    });

    describe('filter[empty]=', () => {
      it('returns filter[Object(empty in \'\')]', () => {
        const q = takeFromQuery(['filter', 'empty']);
        const r = lib(q);
        const expected = {
          column: 'empty',
          operator: 'in',
          value: '',
        };


        expect(r).to.have.property('filter').that.is.an('array');
        expect(r).to.have.property('filter').that.length(1);
        expect(r).to.have.property('filter').that.include(expected);
      });
    });

    describe('parsed filter[array]=[foo, bar]', () => {
      it('returns filter[Object(array in [foo, bar])]', () => {
        const q = takeFromQuery(['filter', 'array']);
        const r = lib(q);
        const expected = {
          column: 'array',
          operator: 'in',
          value: ['foo', 'bar'],
        };

        expect(r).to.have.property('filter').that.is.an('array');
        expect(r).to.have.property('filter').that.length(1);
        expect(r).to.have.property('filter').that.include(expected);
      });
    });

    describe('filter[lt][lt]=20', () => {
      it('returns filter[{ column: lt, operator: <, value: 20 }]', () => {
        const q = takeFromQuery(['filter', 'lt']);
        const r = lib(q);
        const expected = {
          column: 'lt',
          operator: '<',
          value: 20,
        };

        expect(r).to.have.property('filter').that.length(1);
        expect(r).to.have.property('filter').that.include(expected);
      });
    });

    describe('filter[lte][lte]=20', () => {
      it('returns filter[{ column: lte, operator: <=, value: 20 }]', () => {
        const q = takeFromQuery(['filter', 'lte']);
        const r = lib(q);
        const expected = {
          column: 'lte',
          operator: '<=',
          value: 20,
        };

        expect(r).to.have.property('filter').that.length(1);
        expect(r).to.have.property('filter').that.include(expected);
      });
    });
  });
});

@@ -3397,32 +3397,942 @@
 20,%0A        %7D;%0A%0A
+        expect(r).to.have.property('filter').that.length(1);%0A        expect(r).to.have.property('filter').that.include(expected);%0A      %7D);%0A    %7D);%0A%0A    describe('filter%5Bgt%5D%5Bgt%5D=20', () =%3E %7B%0A      it('returns filter%5B%7B column: gt, operator: %3E, value: 20 %7D%5D', () =%3E %7B%0A        const q = takeFromQuery(%5B'filter', 'gt'%5D);%0A        const r = lib(q);%0A        const expected = %7B%0A          column: 'gt',%0A          operator: '%3E',%0A          value: 20,%0A        %7D;%0A%0A        expect(r).to.have.property('filter').that.length(1);%0A        expect(r).to.have.property('filter').that.include(expected);%0A      %7D);%0A    %7D);%0A%0A    describe('filter%5Bgte%5D%5Bgte%5D=20', () =%3E %7B%0A      it('returns filter%5B%7B column: gte, operator: %3E, value: 20 %7D%5D', () =%3E %7B%0A        const q = takeFromQuery(%5B'filter', 'gte'%5D);%0A        const r = lib(q);%0A        const expected = %7B%0A          column: 'gte',%0A          operator: '%3E=',%0A          value: 20,%0A        %7D;%0A%0A
         expect(r

Add test for filter gt and gte