Improve tests

This commit is contained in:
Adria Navarro 2023-01-19 11:06:41 +00:00
parent e13433557a
commit e6dcc47240
1 changed files with 30 additions and 3 deletions

View File

@ -75,7 +75,7 @@ describe("row api - postgres", () => {
}
}
async function populateRows(count: number) {
async function populateRows(count: number, tableId?: string) {
return await Promise.all(
Array(count)
.fill({})
@ -84,7 +84,7 @@ describe("row api - postgres", () => {
return {
rowData,
row: await config.createRow({
tableId: postgresTable._id,
tableId: tableId || postgresTable._id,
...rowData,
}),
}
@ -218,7 +218,18 @@ describe("row api - postgres", () => {
})
describe("search for rows", () => {
test("Given than a table multiple rows, search without query returns all of them", async () => {
test("Given than a table has no rows, search without query returns empty", async () => {
const res = await makeRequest(
"post",
`/tables/${postgresTable._id}/rows/search`
)
expect(res.status).toBe(200)
expect(res.body.data).toHaveLength(0)
})
test("Given than a table has multiple rows, search without query returns all of them", async () => {
const rowsCount = 6
const rows = await populateRows(rowsCount)
@ -236,5 +247,21 @@ describe("row api - postgres", () => {
)
)
})
test("Given than multiple tables have multiple rows, search only return the requested ones", async () => {
await populateRows(2, (await config.createTable())._id)
const rowsCount = 6
await populateRows(rowsCount)
await populateRows(2, (await config.createTable())._id)
const res = await makeRequest(
"post",
`/tables/${postgresTable._id}/rows/search`
)
expect(res.status).toBe(200)
expect(res.body.data).toHaveLength(rowsCount)
})
})
})