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 = FilterBuilder.create();
15 it("should add 'equal' rule", () => {
17 filters.addEqual("etag", "etagValue").serialize()
18 ).toEqual(`[["etag","=","etagValue"]]`);
21 it("should add 'like' rule", () => {
23 filters.addLike("etag", "etagValue").serialize()
24 ).toEqual(`[["etag","like","%etagValue%"]]`);
27 it("should add 'ilike' rule", () => {
29 filters.addILike("etag", "etagValue").serialize()
30 ).toEqual(`[["etag","ilike","%etagValue%"]]`);
33 it("should add 'is_a' rule", () => {
35 filters.addIsA("etag", "etagValue").serialize()
36 ).toEqual(`[["etag","is_a","etagValue"]]`);
39 it("should add 'is_a' rule for set", () => {
41 filters.addIsA("etag", ["etagValue1", "etagValue2"]).serialize()
42 ).toEqual(`[["etag","is_a",["etagValue1","etagValue2"]]]`);
45 it("should add 'in' rule", () => {
47 filters.addIn("etag", "etagValue").serialize()
48 ).toEqual(`[["etag","in","etagValue"]]`);
51 it("should add 'in' rule for set", () => {
53 filters.addIn("etag", ["etagValue1", "etagValue2"]).serialize()
54 ).toEqual(`[["etag","in",["etagValue1","etagValue2"]]]`);
57 it("should add multiple rules", () => {
60 .addIn("etag", ["etagValue1", "etagValue2"])
61 .addEqual("href", "hrefValue")
63 ).toEqual(`[["etag","in",["etagValue1","etagValue2"]],["href","=","hrefValue"]]`);
66 it("should concatenate multiple builders", () => {
69 .concat(FilterBuilder.create().addIn("etag", ["etagValue1", "etagValue2"]))
70 .concat(FilterBuilder.create().addEqual("href", "hrefValue"))
72 ).toEqual(`[["etag","in",["etagValue1","etagValue2"]],["href","=","hrefValue"]]`);
75 it("should add attribute prefix", () => {
78 .addIn("etag", ["etagValue1", "etagValue2"])
80 .toEqual(`[["my_prefix.etag","in",["etagValue1","etagValue2"]]]`);