Add search query tests

This commit is contained in:
Adria Navarro 2023-01-19 11:20:20 +00:00
parent e6dcc47240
commit 2a6d921521
1 changed files with 80 additions and 34 deletions

View File

@ -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))
)
})
})
}) })