Set up first search test that hits SQS et al

This commit is contained in:
Sam Rose 2024-04-09 15:09:56 +01:00
parent 19fe037391
commit 8c3c341c55
No known key found for this signature in database
2 changed files with 75 additions and 1 deletions

View File

@ -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",

View File

@ -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 }),
])
)
})
})