Add search query tests
This commit is contained in:
parent
e6dcc47240
commit
2a6d921521
|
@ -218,6 +218,7 @@ describe("row api - postgres", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("search for rows", () => {
|
describe("search for rows", () => {
|
||||||
|
describe("empty search", () => {
|
||||||
test("Given than a table has no rows, search without query returns empty", async () => {
|
test("Given than a table has no rows, search without query returns empty", async () => {
|
||||||
const res = await makeRequest(
|
const res = await makeRequest(
|
||||||
"post",
|
"post",
|
||||||
|
@ -264,4 +265,49 @@ describe("row api - postgres", () => {
|
||||||
expect(res.body.data).toHaveLength(rowsCount)
|
expect(res.body.data).toHaveLength(rowsCount)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("Given than a table has multiple rows, querying by a string field returns the rows with field containing or starting by that value", async () => {
|
||||||
|
const name = faker.name.fullName()
|
||||||
|
const rowsToFilter = [
|
||||||
|
...Array(2).fill({
|
||||||
|
name,
|
||||||
|
description: faker.lorem.paragraphs(),
|
||||||
|
value: +faker.random.numeric(),
|
||||||
|
}),
|
||||||
|
...Array(2).fill({
|
||||||
|
name: `${name}${faker.random.alphaNumeric(5)}`,
|
||||||
|
description: faker.lorem.paragraphs(),
|
||||||
|
value: +faker.random.numeric(),
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
|
||||||
|
await populateRows(3)
|
||||||
|
for (const row of rowsToFilter) {
|
||||||
|
await config.createRow({
|
||||||
|
tableId: postgresTable._id,
|
||||||
|
...row,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await populateRows(1)
|
||||||
|
|
||||||
|
const res = await makeRequest(
|
||||||
|
"post",
|
||||||
|
`/tables/${postgresTable._id}/rows/search`,
|
||||||
|
{
|
||||||
|
query: {
|
||||||
|
string: {
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
|
||||||
|
expect(res.body.data).toHaveLength(4)
|
||||||
|
expect(res.body.data).toEqual(
|
||||||
|
expect.arrayContaining(rowsToFilter.map(expect.objectContaining))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue