From e13433557ad59c040e7db51ec3640fcd49aa31f2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 19 Jan 2023 11:00:51 +0000 Subject: [PATCH] Add search test --- .../server/src/integration-test/row.spec.ts | 28 ++++++++++++++++++- packages/server/src/tests/jestSetup.ts | 11 +++++--- .../src/tests/utilities/TestConfiguration.ts | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/packages/server/src/integration-test/row.spec.ts b/packages/server/src/integration-test/row.spec.ts index 31f3a138f2..d71e2b2478 100644 --- a/packages/server/src/integration-test/row.spec.ts +++ b/packages/server/src/integration-test/row.spec.ts @@ -10,6 +10,8 @@ import _ from "lodash" const config = setup.getConfig() +jest.unmock("node-fetch") + describe("row api - postgres", () => { let apiKey, makeRequest: MakeRequestResponse, @@ -81,7 +83,10 @@ describe("row api - postgres", () => { const rowData = createRandomRow() return { 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)) }) }) + + 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)) + ) + ) + }) + }) }) diff --git a/packages/server/src/tests/jestSetup.ts b/packages/server/src/tests/jestSetup.ts index fc1477a500..72ea3282c8 100644 --- a/packages/server/src/tests/jestSetup.ts +++ b/packages/server/src/tests/jestSetup.ts @@ -1,9 +1,12 @@ import { mocks } from "@budibase/backend-core/tests" +import env from "../environment" -// mock all dates to 2020-01-01T00:00:00.000Z -// use tk.reset() to use real dates in individual tests -const tk = require("timekeeper") -tk.freeze(mocks.date.MOCK_DATE) +if (!env.isDockerisedTest()) { + // mock all dates to 2020-01-01T00:00:00.000Z + // use tk.reset() to use real dates in individual tests + const tk = require("timekeeper") + tk.freeze(mocks.date.MOCK_DATE) +} if (!process.env.DEBUG) { global.console.log = jest.fn() // console.log are ignored in tests diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index 74e580d8df..2934bafbf2 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -463,7 +463,7 @@ class TestConfiguration { // ROW - async createRow(config: any = null): Promise { + async createRow(config?: Row): Promise { if (!this.table) { throw "Test requires table to be configured." }