From 8c3c341c558645dfcbdd678ed47fc5450d5650c3 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 9 Apr 2024 15:09:56 +0100 Subject: [PATCH] Set up first search test that hits SQS et al --- globalSetup.ts | 2 +- .../src/api/routes/tests/search.spec.ts | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/api/routes/tests/search.spec.ts diff --git a/globalSetup.ts b/globalSetup.ts index 7bf5e2152c..2cfb22f715 100644 --- a/globalSetup.ts +++ b/globalSetup.ts @@ -13,7 +13,7 @@ export default async function setup() { } try { - let couchdb = new GenericContainer("budibase/couchdb") + let couchdb = new GenericContainer("budibase/couchdb:v3.2.1-sqs") .withExposedPorts(5984) .withEnvironment({ COUCHDB_PASSWORD: "budibase", diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts new file mode 100644 index 0000000000..a281d624dc --- /dev/null +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -0,0 +1,74 @@ +import { tableForDatasource } from "../../../tests/utilities/structures" +import { DatabaseName, getDatasource } from "../../../integrations/tests/utils" + +import * as setup from "./utilities" +import { Datasource, FieldType, Table } from "@budibase/types" + +jest.unmock("mssql") + +describe.each([ + ["internal", undefined], + ["internal-sqs", undefined], + [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], + [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], + [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], + [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], +])("/api/:sourceId/search (%s)", (name, dsProvider) => { + const isSqs = name === "internal-sqs" + const config = setup.getConfig() + + let envCleanup: (() => void) | undefined + let table: Table + let datasource: Datasource | undefined + + beforeAll(async () => { + if (isSqs) { + envCleanup = config.setEnv({ SQS_SEARCH_ENABLE: "true" }) + } + await config.init() + if (dsProvider) { + datasource = await config.createDatasource({ + datasource: await dsProvider, + }) + } + }) + + afterAll(async () => { + setup.afterAll() + if (envCleanup) { + envCleanup() + } + }) + + beforeEach(async () => { + table = await config.api.table.save( + tableForDatasource(datasource, { + schema: { + name: { + name: "name", + type: FieldType.STRING, + }, + }, + }) + ) + }) + + it("should return rows", async () => { + const rows = await Promise.all([ + config.api.row.save(table._id!, { name: "foo" }), + config.api.row.save(table._id!, { name: "bar" }), + ]) + + const result = await config.api.row.search(table._id!, { + tableId: table._id!, + query: {}, + }) + + expect(result.rows).toEqual( + expect.arrayContaining([ + expect.objectContaining({ _id: rows[0]._id }), + expect.objectContaining({ _id: rows[1]._id }), + ]) + ) + }) +})