|
- 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());
- });
- });
|