Add tests for array column types, fixing some bugs along the way.
This commit is contained in:
parent
6d8dc7c2f6
commit
d61d5f51cc
|
@ -476,4 +476,78 @@ describe.each([
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("array of strings", () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
await createTable({
|
||||||
|
numbers: {
|
||||||
|
name: "numbers",
|
||||||
|
type: FieldType.ARRAY,
|
||||||
|
constraints: { inclusion: ["one", "two", "three"] },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await createRows([{ numbers: ["one", "two"] }, { numbers: ["three"] }])
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("contains", () => {
|
||||||
|
it("successfully finds a row", () =>
|
||||||
|
expectQuery({ contains: { numbers: ["one"] } }).toContainExactly([
|
||||||
|
{ numbers: ["one", "two"] },
|
||||||
|
]))
|
||||||
|
|
||||||
|
it("fails to find nonexistent row", () =>
|
||||||
|
expectQuery({ contains: { numbers: ["none"] } }).toFindNothing())
|
||||||
|
|
||||||
|
it("fails to find row containing all", () =>
|
||||||
|
expectQuery({
|
||||||
|
contains: { numbers: ["one", "two", "three"] },
|
||||||
|
}).toFindNothing())
|
||||||
|
|
||||||
|
it("finds all with empty list", () =>
|
||||||
|
expectQuery({ contains: { numbers: [] } }).toContainExactly([
|
||||||
|
{ numbers: ["one", "two"] },
|
||||||
|
{ numbers: ["three"] },
|
||||||
|
]))
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("notContains", () => {
|
||||||
|
it("successfully finds a row", () =>
|
||||||
|
expectQuery({ notContains: { numbers: ["one"] } }).toContainExactly([
|
||||||
|
{ numbers: ["three"] },
|
||||||
|
]))
|
||||||
|
|
||||||
|
it("fails to find nonexistent row", () =>
|
||||||
|
expectQuery({
|
||||||
|
notContains: { numbers: ["one", "two", "three"] },
|
||||||
|
}).toContainExactly([
|
||||||
|
{ numbers: ["one", "two"] },
|
||||||
|
{ numbers: ["three"] },
|
||||||
|
]))
|
||||||
|
|
||||||
|
it("finds all with empty list", () =>
|
||||||
|
expectQuery({ notContains: { numbers: [] } }).toContainExactly([
|
||||||
|
{ numbers: ["one", "two"] },
|
||||||
|
{ numbers: ["three"] },
|
||||||
|
]))
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("containsAny", () => {
|
||||||
|
it("successfully finds rows", () =>
|
||||||
|
expectQuery({
|
||||||
|
containsAny: { numbers: ["one", "two", "three"] },
|
||||||
|
}).toContainExactly([
|
||||||
|
{ numbers: ["one", "two"] },
|
||||||
|
{ numbers: ["three"] },
|
||||||
|
]))
|
||||||
|
|
||||||
|
it("fails to find nonexistent row", () =>
|
||||||
|
expectQuery({ containsAny: { numbers: ["none"] } }).toFindNothing())
|
||||||
|
|
||||||
|
it("finds all with empty list", () =>
|
||||||
|
expectQuery({ containsAny: { numbers: [] } }).toContainExactly([
|
||||||
|
{ numbers: ["one", "two"] },
|
||||||
|
{ numbers: ["three"] },
|
||||||
|
]))
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -20,6 +20,7 @@ export enum FilterTypes {
|
||||||
NOT_EMPTY = "notEmpty",
|
NOT_EMPTY = "notEmpty",
|
||||||
CONTAINS = "contains",
|
CONTAINS = "contains",
|
||||||
NOT_CONTAINS = "notContains",
|
NOT_CONTAINS = "notContains",
|
||||||
|
CONTAINS_ANY = "containsAny",
|
||||||
ONE_OF = "oneOf",
|
ONE_OF = "oneOf",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ export const NoEmptyFilterStrings = [
|
||||||
FilterTypes.NOT_EQUAL,
|
FilterTypes.NOT_EQUAL,
|
||||||
FilterTypes.CONTAINS,
|
FilterTypes.CONTAINS,
|
||||||
FilterTypes.NOT_CONTAINS,
|
FilterTypes.NOT_CONTAINS,
|
||||||
|
FilterTypes.CONTAINS_ANY,
|
||||||
]
|
]
|
||||||
|
|
||||||
export const CanSwitchTypes = [
|
export const CanSwitchTypes = [
|
||||||
|
|
|
@ -233,6 +233,11 @@ class InternalBuilder {
|
||||||
(statement ? andOr : "") +
|
(statement ? andOr : "") +
|
||||||
`LOWER(${likeKey(this.client, key)}) LIKE ?`
|
`LOWER(${likeKey(this.client, key)}) LIKE ?`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (statement === "") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
query = query[rawFnc](`${not}(${statement})`, value)
|
query = query[rawFnc](`${not}(${statement})`, value)
|
||||||
})
|
})
|
||||||
|
|
|
@ -29,6 +29,10 @@ function pickApi(tableId: any) {
|
||||||
return internal
|
return internal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isEmptyArray(value: any) {
|
||||||
|
return Array.isArray(value) && value.length === 0
|
||||||
|
}
|
||||||
|
|
||||||
// don't do a pure falsy check, as 0 is included
|
// don't do a pure falsy check, as 0 is included
|
||||||
// https://github.com/Budibase/budibase/issues/10118
|
// https://github.com/Budibase/budibase/issues/10118
|
||||||
export function removeEmptyFilters(filters: SearchFilters) {
|
export function removeEmptyFilters(filters: SearchFilters) {
|
||||||
|
@ -47,7 +51,7 @@ export function removeEmptyFilters(filters: SearchFilters) {
|
||||||
for (let [key, value] of Object.entries(
|
for (let [key, value] of Object.entries(
|
||||||
filters[filterType] as object
|
filters[filterType] as object
|
||||||
)) {
|
)) {
|
||||||
if (value == null || value === "") {
|
if (value == null || value === "" || isEmptyArray(value)) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
delete filters[filterField][key]
|
delete filters[filterField][key]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue