1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { FilterBuilder } from "./filter-builder";
7 describe("FilterBuilder", () => {
9 let filters: FilterBuilder;
12 filters = new FilterBuilder();
15 it("should add 'equal' rule (string)", () => {
17 filters.addEqual("etag", "etagValue").getFilters()
18 ).toEqual(`["etag","=","etagValue"]`);
21 it("should add 'equal' rule (boolean)", () => {
23 filters.addEqual("is_trashed", true).getFilters()
24 ).toEqual(`["is_trashed","=",true]`);
27 it("should add 'like' rule", () => {
29 filters.addLike("etag", "etagValue").getFilters()
30 ).toEqual(`["etag","like","%etagValue%"]`);
33 it("should add 'ilike' rule", () => {
35 filters.addILike("etag", "etagValue").getFilters()
36 ).toEqual(`["etag","ilike","%etagValue%"]`);
39 it("should add 'is_a' rule", () => {
41 filters.addIsA("etag", "etagValue").getFilters()
42 ).toEqual(`["etag","is_a","etagValue"]`);
45 it("should add 'is_a' rule for set", () => {
47 filters.addIsA("etag", ["etagValue1", "etagValue2"]).getFilters()
48 ).toEqual(`["etag","is_a",["etagValue1","etagValue2"]]`);
51 it("should add 'in' rule", () => {
53 filters.addIn("etag", "etagValue").getFilters()
54 ).toEqual(`["etag","in","etagValue"]`);
57 it("should add 'in' rule for set", () => {
59 filters.addIn("etag", ["etagValue1", "etagValue2"]).getFilters()
60 ).toEqual(`["etag","in",["etagValue1","etagValue2"]]`);
63 it("should add 'not in' rule for set", () => {
65 filters.addNotIn("etag", ["etagValue1", "etagValue2"]).getFilters()
66 ).toEqual(`["etag","not in",["etagValue1","etagValue2"]]`);
69 it("should add multiple rules", () => {
72 .addIn("etag", ["etagValue1", "etagValue2"])
73 .addEqual("href", "hrefValue")
75 ).toEqual(`["etag","in",["etagValue1","etagValue2"]],["href","=","hrefValue"]`);
78 it("should add attribute prefix", () => {
79 expect(new FilterBuilder()
80 .addIn("etag", ["etagValue1", "etagValue2"], "myPrefix")
82 .toEqual(`["myPrefix.etag","in",["etagValue1","etagValue2"]]`);
85 it('should add full text search', () => {
88 .addFullTextSearch('my custom search')
90 ).toEqual(`["any","ilike","%my%"],["any","ilike","%custom%"],["any","ilike","%search%"]`);