1
0
Fork 0
mirror of synced 2024-08-12 16:41:26 +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 { 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

View file

@ -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 () => {

View file

@ -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()

View file

@ -1,11 +1,17 @@
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> {
try {
if (!container) { 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) .withExposedPorts(5432)
.withEnv("POSTGRES_PASSWORD", "password") .withEnv("POSTGRES_PASSWORD", "password")
.withWaitStrategy( .withWaitStrategy(
@ -15,7 +21,6 @@ export async function getDsConfig(): Promise<Datasource> {
) )
.start() .start()
} }
const host = container.getContainerIpAddress() const host = container.getContainerIpAddress()
const port = container.getMappedPort(5432) const port = container.getMappedPort(5432)
@ -35,6 +40,9 @@ export async function getDsConfig(): Promise<Datasource> {
ca: false, ca: false,
}, },
} }
} catch (err) {
throw new Error("**UNABLE TO CREATE TO POSTGRES CONTAINER**")
}
} }
export async function stopContainer() { export async function stopContainer() {

View file

@ -570,12 +570,10 @@ 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,12 +606,10 @@ 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)
} }

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 * 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.