Add search test
This commit is contained in:
parent
e5509d86de
commit
e13433557a
|
@ -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))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import { mocks } from "@budibase/backend-core/tests"
|
import { mocks } from "@budibase/backend-core/tests"
|
||||||
|
import env from "../environment"
|
||||||
|
|
||||||
|
if (!env.isDockerisedTest()) {
|
||||||
// mock all dates to 2020-01-01T00:00:00.000Z
|
// mock all dates to 2020-01-01T00:00:00.000Z
|
||||||
// use tk.reset() to use real dates in individual tests
|
// use tk.reset() to use real dates in individual tests
|
||||||
const tk = require("timekeeper")
|
const tk = require("timekeeper")
|
||||||
tk.freeze(mocks.date.MOCK_DATE)
|
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
|
||||||
|
|
|
@ -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."
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue