|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- import {describe, expect, it} from 'vitest';
- import { convertToDataSourceQueryCollection } from '../../src/backend';
-
- describe('query', () => {
- it('returns a data source query collection from search params', () => {
- const q = new URLSearchParams();
- const collection = convertToDataSourceQueryCollection(q);
- expect(collection).toBeInstanceOf(Array);
- });
-
- it('returns an equal query', () => {
- const q = new URLSearchParams({
- attr: 'foo'
- });
- const collection = convertToDataSourceQueryCollection(q);
- expect(collection).toEqual([
- {
- lhs: 'attr',
- operator: '=',
- rhs: '"foo"',
- },
- ]);
- });
-
- it('returns an equal expression query', () => {
- const q = new URLSearchParams({
- attr: '.eq.foo'
- });
- const collection = convertToDataSourceQueryCollection(q);
- expect(collection).toEqual([
- {
- lhs: 'attr',
- operator: '=',
- rhs: '"foo"',
- },
- ]);
- });
-
- it('returns a not equal expression query', () => {
- const q = new URLSearchParams({
- attr: '.neq.foo'
- });
- const collection = convertToDataSourceQueryCollection(q);
- expect(collection).toEqual([
- {
- lhs: 'attr',
- operator: '!=',
- rhs: '"foo"',
- },
- ]);
- });
-
- it('returns a greater than expression query', () => {
- const q = new URLSearchParams({
- attr: '.gt.foo'
- });
- const collection = convertToDataSourceQueryCollection(q);
- expect(collection).toEqual([
- {
- lhs: 'attr',
- operator: '>',
- rhs: '"foo"',
- },
- ]);
- });
-
- it('returns a less than expression query', () => {
- const q = new URLSearchParams({
- attr: '.lt.foo'
- });
- const collection = convertToDataSourceQueryCollection(q);
- expect(collection).toEqual([
- {
- lhs: 'attr',
- operator: '<',
- rhs: '"foo"',
- },
- ]);
- });
-
- it.only('returns a greater than or equal expression query', () => {
- // expect(
- // convertToDataSourceQueryCollection(
- // new URLSearchParams({
- // attr: '.gt.eq.foo'
- // })
- // )
- // ).toEqual([
- // {
- // lhs: 'attr',
- // operator: '>=',
- // rhs: '"foo"',
- // },
- // ]);
- expect(
- convertToDataSourceQueryCollection(
- new URLSearchParams({
- attr: '.gte.foo'
- })
- )
- ).toEqual([
- {
- lhs: 'attr',
- operator: '>=',
- rhs: '"foo"',
- },
- ]);
-
- expect(
- convertToDataSourceQueryCollection(
- new URLSearchParams({
- attr: '.neq.test'
- })
- )
- ).toEqual([
- {
- lhs: 'attr',
- operator: '!=',
- rhs: '"test"',
- },
- ]);
-
- // expect(
- // convertToDataSourceQueryCollection(
- // new URLSearchParams({
- // attr: '.gte.foo..test'
- // })
- // )
- // ).toEqual([
- // {
- // lhs: 'attr',
- // operator: '>=',
- // rhs: '"foo.test"',
- // },
- // ]);
- });
-
- it('returns a less than or equal expression query', () => {
- const q = new URLSearchParams({
- attr: '.lt.eq.foo'
- });
- const collection = convertToDataSourceQueryCollection(q);
- expect(collection).toEqual([
- {
- lhs: 'attr',
- operator: '<=',
- rhs: '"foo"',
- },
- ]);
- });
-
- it('returns an AND operator query', () => {
- const q = new URLSearchParams([
- ['attr', 'foo'],
- ['attr', 'bar'],
- ]);
- const collection = convertToDataSourceQueryCollection(q);
- expect(collection).toEqual([
- {
- lhs: 'attr',
- operator: '=',
- rhs: '"foo"',
- },
- {
- lhs: 'attr',
- operator: '=',
- rhs: '"bar"',
- },
- ]);
- });
-
- it.skip('returns a query', () => {
- // * is not percent-encoded
- // . is not percent-encoded (used for form data such as input text dir...)
- //
- const q = new URLSearchParams({
- '.foo': 'foo',
- });
-
- console.log(q.toString());
- });
- });
|