Fixing some test cases.
This commit is contained in:
parent
ed0670a008
commit
19eaafd946
|
@ -10,6 +10,7 @@ import { events } from "@budibase/backend-core"
|
||||||
import {
|
import {
|
||||||
BulkImportRequest,
|
BulkImportRequest,
|
||||||
BulkImportResponse,
|
BulkImportResponse,
|
||||||
|
DocumentType,
|
||||||
FetchTablesResponse,
|
FetchTablesResponse,
|
||||||
MigrateRequest,
|
MigrateRequest,
|
||||||
MigrateResponse,
|
MigrateResponse,
|
||||||
|
@ -20,6 +21,7 @@ import {
|
||||||
TableResponse,
|
TableResponse,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
UserCtx,
|
UserCtx,
|
||||||
|
SEPARATOR,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import sdk from "../../../sdk"
|
import sdk from "../../../sdk"
|
||||||
import { jsonFromCsvString } from "../../../utilities/csv"
|
import { jsonFromCsvString } from "../../../utilities/csv"
|
||||||
|
@ -30,7 +32,12 @@ function pickApi({ tableId, table }: { tableId?: string; table?: Table }) {
|
||||||
if (table && !tableId) {
|
if (table && !tableId) {
|
||||||
tableId = table._id
|
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
|
return external
|
||||||
} else if (tableId && isExternalTable(tableId)) {
|
} else if (tableId && isExternalTable(tableId)) {
|
||||||
return external
|
return external
|
||||||
|
|
|
@ -245,7 +245,8 @@ describe("/tables", () => {
|
||||||
.expect(200)
|
.expect(200)
|
||||||
const fetchedTable = res.body[0]
|
const fetchedTable = res.body[0]
|
||||||
expect(fetchedTable.name).toEqual(testTable.name)
|
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 () => {
|
it("should apply authorization to endpoint", async () => {
|
||||||
|
|
|
@ -75,7 +75,6 @@ const environment = {
|
||||||
},
|
},
|
||||||
isTest: coreEnv.isTest,
|
isTest: coreEnv.isTest,
|
||||||
isJest: coreEnv.isJest,
|
isJest: coreEnv.isJest,
|
||||||
|
|
||||||
isDev: coreEnv.isDev,
|
isDev: coreEnv.isDev,
|
||||||
isProd: () => {
|
isProd: () => {
|
||||||
return !coreEnv.isDev()
|
return !coreEnv.isDev()
|
||||||
|
|
|
@ -1,39 +1,47 @@
|
||||||
import { Datasource, SourceName } from "@budibase/types"
|
import { Datasource, SourceName } from "@budibase/types"
|
||||||
import { GenericContainer, Wait, StartedTestContainer } from "testcontainers"
|
import { GenericContainer, Wait, StartedTestContainer } from "testcontainers"
|
||||||
|
import env from "../../../environment"
|
||||||
|
|
||||||
let container: StartedTestContainer | undefined
|
let container: StartedTestContainer | undefined
|
||||||
|
|
||||||
|
const isMac = process.platform === "darwin"
|
||||||
|
|
||||||
export async function getDsConfig(): Promise<Datasource> {
|
export async function getDsConfig(): Promise<Datasource> {
|
||||||
if (!container) {
|
try {
|
||||||
container = await new GenericContainer("postgres")
|
if (!container) {
|
||||||
.withExposedPorts(5432)
|
// postgres 15-bullseye safer bet on Linux
|
||||||
.withEnv("POSTGRES_PASSWORD", "password")
|
const version = isMac ? undefined : "15-bullseye"
|
||||||
.withWaitStrategy(
|
container = await new GenericContainer("postgres", version)
|
||||||
Wait.forLogMessage(
|
.withExposedPorts(5432)
|
||||||
"PostgreSQL init process complete; ready for start up."
|
.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()
|
return {
|
||||||
const port = container.getMappedPort(5432)
|
type: "datasource_plus",
|
||||||
|
source: SourceName.POSTGRES,
|
||||||
return {
|
plus: true,
|
||||||
type: "datasource_plus",
|
config: {
|
||||||
source: SourceName.POSTGRES,
|
host,
|
||||||
plus: true,
|
port,
|
||||||
config: {
|
database: "postgres",
|
||||||
host,
|
user: "postgres",
|
||||||
port,
|
password: "password",
|
||||||
database: "postgres",
|
schema: "public",
|
||||||
user: "postgres",
|
ssl: false,
|
||||||
password: "password",
|
rejectUnauthorized: false,
|
||||||
schema: "public",
|
ca: false,
|
||||||
ssl: false,
|
},
|
||||||
rejectUnauthorized: false,
|
}
|
||||||
ca: false,
|
} catch (err) {
|
||||||
},
|
throw new Error("**UNABLE TO CREATE TO POSTGRES CONTAINER**")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -570,11 +570,9 @@ class TestConfiguration {
|
||||||
if (!config.sourceId) {
|
if (!config.sourceId) {
|
||||||
config.sourceId = INTERNAL_TABLE_SOURCE_ID
|
config.sourceId = INTERNAL_TABLE_SOURCE_ID
|
||||||
}
|
}
|
||||||
if (this.datasource && !config.sourceId) {
|
if (this.datasource?._id) {
|
||||||
config.sourceId = this.datasource._id || INTERNAL_TABLE_SOURCE_ID
|
config.sourceId = this.datasource._id
|
||||||
if (this.datasource.plus) {
|
config.sourceType = TableSourceType.EXTERNAL
|
||||||
config.sourceType = TableSourceType.EXTERNAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.updateTable(config, options)
|
return this.updateTable(config, options)
|
||||||
|
@ -608,11 +606,9 @@ class TestConfiguration {
|
||||||
} as RelationshipFieldMetadata
|
} as RelationshipFieldMetadata
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.datasource && !tableConfig.sourceId) {
|
if (this.datasource?._id) {
|
||||||
tableConfig.sourceId = this.datasource._id || INTERNAL_TABLE_SOURCE_ID
|
tableConfig.sourceId = this.datasource._id
|
||||||
if (this.datasource.plus) {
|
tableConfig.sourceType = TableSourceType.EXTERNAL
|
||||||
tableConfig.sourceType = TableSourceType.EXTERNAL
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.createTable(tableConfig)
|
return await this.createTable(tableConfig)
|
||||||
|
|
|
@ -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
|
* 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.
|
* 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 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 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.
|
* @param opts specific options for function to carry out optional features.
|
||||||
|
|
Loading…
Reference in New Issue