Add more search tests.
This commit is contained in:
parent
c753ffede9
commit
d96bf29bef
|
@ -2,7 +2,13 @@ import { tableForDatasource } from "../../../tests/utilities/structures"
|
||||||
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
||||||
|
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
import { Datasource, FieldType, Table } from "@budibase/types"
|
import {
|
||||||
|
Datasource,
|
||||||
|
FieldType,
|
||||||
|
SearchFilter,
|
||||||
|
SearchFilters,
|
||||||
|
Table,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
jest.unmock("mssql")
|
jest.unmock("mssql")
|
||||||
|
|
||||||
|
@ -53,22 +59,41 @@ describe.each([
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return rows", async () => {
|
describe("strings", () => {
|
||||||
const rows = await Promise.all([
|
interface StringSearchTest {
|
||||||
config.api.row.save(table._id!, { name: "foo" }),
|
query: SearchFilters
|
||||||
config.api.row.save(table._id!, { name: "bar" }),
|
expected: number[]
|
||||||
])
|
}
|
||||||
|
|
||||||
const result = await config.api.row.search(table._id!, {
|
const stringSearchTests: StringSearchTest[] = [
|
||||||
tableId: table._id!,
|
{ query: {}, expected: [0, 1] },
|
||||||
query: {},
|
{ query: { string: { name: "foo" } }, expected: [0] },
|
||||||
})
|
{ query: { fuzzy: { name: "oo" } }, expected: [0] },
|
||||||
|
{ query: { equal: { name: "foo" } }, expected: [0] },
|
||||||
|
{ query: { notEqual: { name: "foo" } }, expected: [1] },
|
||||||
|
{ query: { oneOf: { name: ["foo"] } }, expected: [0] },
|
||||||
|
// { query: { contains: { name: "f" } }, expected: [0] },
|
||||||
|
// { query: { notContains: { name: ["f"] } }, expected: [1] },
|
||||||
|
// { query: { containsAny: { name: ["f"] } }, expected: [0] },
|
||||||
|
]
|
||||||
|
|
||||||
expect(result.rows).toEqual(
|
it.each(stringSearchTests)(
|
||||||
expect.arrayContaining([
|
`should be able to run query: $query`,
|
||||||
expect.objectContaining({ _id: rows[0]._id }),
|
async ({ query, expected }) => {
|
||||||
expect.objectContaining({ _id: rows[1]._id }),
|
const rows = await Promise.all([
|
||||||
])
|
config.api.row.save(table._id!, { name: "foo" }),
|
||||||
|
config.api.row.save(table._id!, { name: "bar" }),
|
||||||
|
])
|
||||||
|
|
||||||
|
const result = await config.api.row.search(table._id!, {
|
||||||
|
tableId: table._id!,
|
||||||
|
query,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.rows.map(r => r._id)).toEqual(
|
||||||
|
expect.arrayContaining(expected.map(i => rows[i]._id))
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue