Test relationships

This commit is contained in:
Adria Navarro 2024-08-12 12:57:07 +02:00
parent ee5c4e8ed8
commit 59a164f4df
2 changed files with 37 additions and 8 deletions

View File

@ -31,14 +31,10 @@ export const removeInvalidFilters = (
const filter = result[filterKey]
for (const columnKey of Object.keys(filter)) {
if (
!validFields
.map(f => f.toLowerCase())
.includes(columnKey.toLowerCase()) &&
!validFields
.map(f => f.toLowerCase())
.includes(db.removeKeyNumbering(columnKey).toLowerCase())
) {
const possibleKeys = [columnKey, db.removeKeyNumbering(columnKey)].map(
c => c.toLowerCase()
)
if (!validFields.some(f => possibleKeys.includes(f.toLowerCase()))) {
delete filter[columnKey]
}
}

View File

@ -145,5 +145,38 @@ describe("query utils", () => {
},
})
})
it("handles relationship filters", () => {
const prefixedFilters: SearchFilters = {
$or: {
conditions: [
{ equal: { "1:other.one": "foo" } },
{
equal: {
"2:other.one": "foo2",
"3:other.two": "bar",
"4:other.three": "baz",
},
},
{ equal: { "another.three": "baz2" } },
],
},
}
const result = removeInvalidFilters(prefixedFilters, [
"other.one",
"other.two",
"another.three",
])
expect(result).toEqual({
$or: {
conditions: [
{ equal: { "1:other.one": "foo" } },
{ equal: { "2:other.one": "foo2", "3:other.two": "bar" } },
{ equal: { "another.three": "baz2" } },
],
},
})
})
})
})