Remove auth client
[arvados-workbench2.git] / src / common / api / filter-builder.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { FilterBuilder } from "./filter-builder";
6
7 describe("FilterBuilder", () => {
8
9     let filters: FilterBuilder;
10
11     beforeEach(() => {
12         filters = FilterBuilder.create();
13     });
14
15     it("should add 'equal' rule", () => {
16         expect(
17             filters.addEqual("etag", "etagValue").serialize()
18         ).toEqual(`[["etag","=","etagValue"]]`);
19     });
20
21     it("should add 'like' rule", () => {
22         expect(
23             filters.addLike("etag", "etagValue").serialize()
24         ).toEqual(`[["etag","like","%etagValue%"]]`);
25     });
26
27     it("should add 'ilike' rule", () => {
28         expect(
29             filters.addILike("etag", "etagValue").serialize()
30         ).toEqual(`[["etag","ilike","%etagValue%"]]`);
31     });
32
33     it("should add 'is_a' rule", () => {
34         expect(
35             filters.addIsA("etag", "etagValue").serialize()
36         ).toEqual(`[["etag","is_a","etagValue"]]`);
37     });
38
39     it("should add 'is_a' rule for set", () => {
40         expect(
41             filters.addIsA("etag", ["etagValue1", "etagValue2"]).serialize()
42         ).toEqual(`[["etag","is_a",["etagValue1","etagValue2"]]]`);
43     });
44
45     it("should add 'in' rule", () => {
46         expect(
47             filters.addIn("etag", "etagValue").serialize()
48         ).toEqual(`[["etag","in","etagValue"]]`);
49     });
50
51     it("should add 'in' rule for set", () => {
52         expect(
53             filters.addIn("etag", ["etagValue1", "etagValue2"]).serialize()
54         ).toEqual(`[["etag","in",["etagValue1","etagValue2"]]]`);
55     });
56
57     it("should add multiple rules", () => {
58         expect(
59             filters
60                 .addIn("etag", ["etagValue1", "etagValue2"])
61                 .addEqual("href", "hrefValue")
62                 .serialize()
63         ).toEqual(`[["etag","in",["etagValue1","etagValue2"]],["href","=","hrefValue"]]`);
64     });
65
66     it("should concatenate multiple builders", () => {
67         expect(
68             filters
69                 .concat(FilterBuilder.create().addIn("etag", ["etagValue1", "etagValue2"]))
70                 .concat(FilterBuilder.create().addEqual("href", "hrefValue"))
71                 .serialize()
72         ).toEqual(`[["etag","in",["etagValue1","etagValue2"]],["href","=","hrefValue"]]`);
73     });
74
75     it("should add attribute prefix", () => {
76         expect(FilterBuilder
77             .create("myPrefix")
78             .addIn("etag", ["etagValue1", "etagValue2"])
79             .serialize())
80             .toEqual(`[["my_prefix.etag","in",["etagValue1","etagValue2"]]]`);
81     });
82
83
84
85
86 });