|
| 1 | +import { expect } from "chai"; |
| 2 | + |
| 3 | +import { filterEntityList } from "../../src/utils/filter"; |
| 4 | + |
| 5 | +describe("entity filter", () => { |
| 6 | + const entities = [ |
| 7 | + { name: "A", path: "/root/entity/a" }, |
| 8 | + { name: "B", path: "/root/entity/b" }, |
| 9 | + { name: "C", path: "/root/entity/c" }, |
| 10 | + { name: "D", path: "/root/entity/d" }, |
| 11 | + ]; |
| 12 | + |
| 13 | + it("should filter an entity list with paths", () => { |
| 14 | + const filterObjects = [{ path: "/root/entity/b" }, { path: "/root/entity/c" }]; |
| 15 | + const filtered = filterEntityList({ filterObjects, entitiesOrPaths: entities }); |
| 16 | + const expected = [ |
| 17 | + { name: "B", path: "/root/entity/b" }, |
| 18 | + { name: "C", path: "/root/entity/c" }, |
| 19 | + ]; |
| 20 | + expect(filtered).to.have.deep.members(expected); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should filter an entity list with regular expressions", () => { |
| 24 | + const filterObjects = [{ regex: /\/root\/entity\/[bc]/ }]; |
| 25 | + const filtered = filterEntityList({ filterObjects, entitiesOrPaths: entities }); |
| 26 | + const expected = [ |
| 27 | + { name: "B", path: "/root/entity/b" }, |
| 28 | + { name: "C", path: "/root/entity/c" }, |
| 29 | + ]; |
| 30 | + expect(filtered).to.have.deep.members(expected); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should filter an entity list with both paths and regular expressions", () => { |
| 34 | + const filterObjects = [{ path: "/root/entity/b" }, { regex: /\/root\/entity\/[c]/ }]; |
| 35 | + const filtered = filterEntityList({ filterObjects, entitiesOrPaths: entities }); |
| 36 | + const expected = [ |
| 37 | + { name: "B", path: "/root/entity/b" }, |
| 38 | + { name: "C", path: "/root/entity/c" }, |
| 39 | + ]; |
| 40 | + expect(filtered).to.have.deep.members(expected); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should filter an entity list containing concatenated paths", () => { |
| 44 | + const filterObjects = [{ path: "/root/entity/b" }, { path: "/root/entity/c" }]; |
| 45 | + const multiPathEntities = [ |
| 46 | + { name: "AB", path: "/root/entity/a::/root/entity/b" }, |
| 47 | + { name: "BC", path: "/root/entity/b::/root/entity/c" }, |
| 48 | + ]; |
| 49 | + const multiPathSeparator = "::"; |
| 50 | + const filtered = filterEntityList({ |
| 51 | + filterObjects, |
| 52 | + entitiesOrPaths: multiPathEntities, |
| 53 | + multiPathSeparator, |
| 54 | + }); |
| 55 | + const expected = [{ name: "BC", path: "/root/entity/b::/root/entity/c" }]; |
| 56 | + expect(filtered).to.have.deep.members(expected); |
| 57 | + }); |
| 58 | + |
| 59 | + it("should filter an entity list containing concatenated paths using regex", () => { |
| 60 | + const filterObjects = [{ path: "/root/entity/b" }, { regex: /\/root\/entity\/[c]/ }]; |
| 61 | + const multiPathEntities = [ |
| 62 | + { name: "AB", path: "/root/entity/a::/root/entity/b" }, |
| 63 | + { name: "BC", path: "/root/entity/b::/root/entity/c" }, |
| 64 | + ]; |
| 65 | + const multiPathSeparator = "::"; |
| 66 | + const filtered = filterEntityList({ |
| 67 | + filterObjects, |
| 68 | + entitiesOrPaths: multiPathEntities, |
| 69 | + multiPathSeparator, |
| 70 | + }); |
| 71 | + const expected = [{ name: "BC", path: "/root/entity/b::/root/entity/c" }]; |
| 72 | + expect(filtered).to.have.deep.members(expected); |
| 73 | + }); |
| 74 | +}); |
0 commit comments