Test relationships
This commit is contained in:
parent
ee5c4e8ed8
commit
59a164f4df
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" } },
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue