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 multiple rules", () => {
66 .addIn("etag", ["etagValue1", "etagValue2"])
67 .addEqual("href", "hrefValue")
69 ).toEqual(`["etag","in",["etagValue1","etagValue2"]],["href","=","hrefValue"]`);
72 it("should add attribute prefix", () => {
73 expect(new FilterBuilder()
74 .addIn("etag", ["etagValue1", "etagValue2"], "myPrefix")
76 .toEqual(`["my_prefix.etag","in",["etagValue1","etagValue2"]]`);