Add search test

This commit is contained in:
Adria Navarro 2023-01-19 11:00:51 +00:00
parent e5509d86de
commit e13433557a
3 changed files with 35 additions and 6 deletions

View File

@ -10,6 +10,8 @@ import _ from "lodash"
const config = setup.getConfig() const config = setup.getConfig()
jest.unmock("node-fetch")
describe("row api - postgres", () => { describe("row api - postgres", () => {
let apiKey, let apiKey,
makeRequest: MakeRequestResponse, makeRequest: MakeRequestResponse,
@ -81,7 +83,10 @@ describe("row api - postgres", () => {
const rowData = createRandomRow() const rowData = createRandomRow()
return { return {
rowData, rowData,
row: await config.createRow(rowData), row: await config.createRow({
tableId: postgresTable._id,
...rowData,
}),
} }
}) })
) )
@ -211,4 +216,25 @@ describe("row api - postgres", () => {
expect(res.body.data).toEqual(expect.objectContaining(rowData)) expect(res.body.data).toEqual(expect.objectContaining(rowData))
}) })
}) })
describe("search for rows", () => {
test("Given than a table multiple rows, search without query returns all of them", async () => {
const rowsCount = 6
const rows = await populateRows(rowsCount)
const res = await makeRequest(
"post",
`/tables/${postgresTable._id}/rows/search`
)
expect(res.status).toBe(200)
expect(res.body.data).toHaveLength(rowsCount)
expect(res.body.data).toEqual(
expect.arrayContaining(
rows.map(r => expect.objectContaining(r.rowData))
)
)
})
})
}) })

View File

@ -1,9 +1,12 @@
import { mocks } from "@budibase/backend-core/tests" import { mocks } from "@budibase/backend-core/tests"
import env from "../environment"
// mock all dates to 2020-01-01T00:00:00.000Z if (!env.isDockerisedTest()) {
// use tk.reset() to use real dates in individual tests // mock all dates to 2020-01-01T00:00:00.000Z
const tk = require("timekeeper") // use tk.reset() to use real dates in individual tests
tk.freeze(mocks.date.MOCK_DATE) const tk = require("timekeeper")
tk.freeze(mocks.date.MOCK_DATE)
}
if (!process.env.DEBUG) { if (!process.env.DEBUG) {
global.console.log = jest.fn() // console.log are ignored in tests global.console.log = jest.fn() // console.log are ignored in tests

View File

@ -463,7 +463,7 @@ class TestConfiguration {
// ROW // ROW
async createRow(config: any = null): Promise<Row> { async createRow(config?: Row): Promise<Row> {
if (!this.table) { if (!this.table) {
throw "Test requires table to be configured." throw "Test requires table to be configured."
} }