Fixing some test cases.

This commit is contained in:
mike12345567 2023-10-26 16:32:34 +01:00
parent ed0670a008
commit 19eaafd946
6 changed files with 53 additions and 42 deletions

View File

@ -10,6 +10,7 @@ import { events } from "@budibase/backend-core"
import {
BulkImportRequest,
BulkImportResponse,
DocumentType,
FetchTablesResponse,
MigrateRequest,
MigrateResponse,
@ -20,6 +21,7 @@ import {
TableResponse,
TableSourceType,
UserCtx,
SEPARATOR,
} from "@budibase/types"
import sdk from "../../../sdk"
import { jsonFromCsvString } from "../../../utilities/csv"
@ -30,7 +32,12 @@ function pickApi({ tableId, table }: { tableId?: string; table?: Table }) {
if (table && !tableId) {
tableId = table._id
}
if (table && table.sourceType === TableSourceType.EXTERNAL) {
if (
table?.sourceId &&
table.sourceId.includes(DocumentType.DATASOURCE + SEPARATOR)
) {
return external
} else if (table?.sourceType === TableSourceType.EXTERNAL) {
return external
} else if (tableId && isExternalTable(tableId)) {
return external

View File

@ -245,7 +245,8 @@ describe("/tables", () => {
.expect(200)
const fetchedTable = res.body[0]
expect(fetchedTable.name).toEqual(testTable.name)
expect(fetchedTable.type).toEqual("internal")
expect(fetchedTable.type).toEqual("table")
expect(fetchedTable.sourceType).toEqual("internal")
})
it("should apply authorization to endpoint", async () => {

View File

@ -75,7 +75,6 @@ const environment = {
},
isTest: coreEnv.isTest,
isJest: coreEnv.isJest,
isDev: coreEnv.isDev,
isProd: () => {
return !coreEnv.isDev()

View File

@ -1,11 +1,17 @@
import { Datasource, SourceName } from "@budibase/types"
import { GenericContainer, Wait, StartedTestContainer } from "testcontainers"
import env from "../../../environment"
let container: StartedTestContainer | undefined
const isMac = process.platform === "darwin"
export async function getDsConfig(): Promise<Datasource> {
try {
if (!container) {
container = await new GenericContainer("postgres")
// postgres 15-bullseye safer bet on Linux
const version = isMac ? undefined : "15-bullseye"
container = await new GenericContainer("postgres", version)
.withExposedPorts(5432)
.withEnv("POSTGRES_PASSWORD", "password")
.withWaitStrategy(
@ -15,7 +21,6 @@ export async function getDsConfig(): Promise<Datasource> {
)
.start()
}
const host = container.getContainerIpAddress()
const port = container.getMappedPort(5432)
@ -35,6 +40,9 @@ export async function getDsConfig(): Promise<Datasource> {
ca: false,
},
}
} catch (err) {
throw new Error("**UNABLE TO CREATE TO POSTGRES CONTAINER**")
}
}
export async function stopContainer() {

View File

@ -570,12 +570,10 @@ class TestConfiguration {
if (!config.sourceId) {
config.sourceId = INTERNAL_TABLE_SOURCE_ID
}
if (this.datasource && !config.sourceId) {
config.sourceId = this.datasource._id || INTERNAL_TABLE_SOURCE_ID
if (this.datasource.plus) {
if (this.datasource?._id) {
config.sourceId = this.datasource._id
config.sourceType = TableSourceType.EXTERNAL
}
}
return this.updateTable(config, options)
}
@ -608,12 +606,10 @@ class TestConfiguration {
} as RelationshipFieldMetadata
}
if (this.datasource && !tableConfig.sourceId) {
tableConfig.sourceId = this.datasource._id || INTERNAL_TABLE_SOURCE_ID
if (this.datasource.plus) {
if (this.datasource?._id) {
tableConfig.sourceId = this.datasource._id
tableConfig.sourceType = TableSourceType.EXTERNAL
}
}
return await this.createTable(tableConfig)
}

View File

@ -51,7 +51,7 @@ function getRemovedAttachmentKeys(
/**
* This will update any auto columns that are found on the row/table with the correct information based on
* time now and the current logged in user making the request.
* @param user The user to be used for an appId as well as the createdBy and createdAt fields.
* @param userId The user to be used for an appId as well as the createdBy and createdAt fields.
* @param table The table which is to be used for the schema, as well as handling auto IDs incrementing.
* @param row The row which is to be updated with information for the auto columns.
* @param opts specific options for function to carry out optional features.