1
0
Fork 0
mirror of synced 2024-07-07 07:15:43 +12:00

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,39 +1,47 @@
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> {
if (!container) {
container = await new GenericContainer("postgres")
.withExposedPorts(5432)
.withEnv("POSTGRES_PASSWORD", "password")
.withWaitStrategy(
Wait.forLogMessage(
"PostgreSQL init process complete; ready for start up."
try {
if (!container) {
// 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(
Wait.forLogMessage(
"PostgreSQL init process complete; ready for start up."
)
)
)
.start()
}
.start()
}
const host = container.getContainerIpAddress()
const port = container.getMappedPort(5432)
const host = container.getContainerIpAddress()
const port = container.getMappedPort(5432)
return {
type: "datasource_plus",
source: SourceName.POSTGRES,
plus: true,
config: {
host,
port,
database: "postgres",
user: "postgres",
password: "password",
schema: "public",
ssl: false,
rejectUnauthorized: false,
ca: false,
},
return {
type: "datasource_plus",
source: SourceName.POSTGRES,
plus: true,
config: {
host,
port,
database: "postgres",
user: "postgres",
password: "password",
schema: "public",
ssl: false,
rejectUnauthorized: false,
ca: false,
},
}
} catch (err) {
throw new Error("**UNABLE TO CREATE TO POSTGRES CONTAINER**")
}
}

View file

@ -570,11 +570,9 @@ 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) {
config.sourceType = TableSourceType.EXTERNAL
}
if (this.datasource?._id) {
config.sourceId = this.datasource._id
config.sourceType = TableSourceType.EXTERNAL
}
return this.updateTable(config, options)
@ -608,11 +606,9 @@ class TestConfiguration {
} as RelationshipFieldMetadata
}
if (this.datasource && !tableConfig.sourceId) {
tableConfig.sourceId = this.datasource._id || INTERNAL_TABLE_SOURCE_ID
if (this.datasource.plus) {
tableConfig.sourceType = TableSourceType.EXTERNAL
}
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.