Introduce integration tests for `POST /api/datasources/:datasourceId/schema`
This commit is contained in:
parent
2f0e88c17c
commit
e1af1a5be3
|
@ -69,18 +69,20 @@ async function buildFilteredSchema(
|
||||||
filter?: string[]
|
filter?: string[]
|
||||||
): Promise<Schema> {
|
): Promise<Schema> {
|
||||||
let schema = await buildSchemaHelper(datasource)
|
let schema = await buildSchemaHelper(datasource)
|
||||||
let filteredSchema: Schema = { tables: {}, errors: {} }
|
if (!filter) {
|
||||||
if (filter) {
|
return schema
|
||||||
for (let key in schema.tables) {
|
}
|
||||||
if (filter.some(filter => filter.toLowerCase() === key.toLowerCase())) {
|
|
||||||
filteredSchema.tables[key] = schema.tables[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let key in schema.errors) {
|
let filteredSchema: Schema = { tables: {}, errors: {} }
|
||||||
if (filter.some(filter => filter.toLowerCase() === key.toLowerCase())) {
|
for (let key in schema.tables) {
|
||||||
filteredSchema.errors[key] = schema.errors[key]
|
if (filter.some(filter => filter.toLowerCase() === key.toLowerCase())) {
|
||||||
}
|
filteredSchema.tables[key] = schema.tables[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let key in schema.errors) {
|
||||||
|
if (filter.some(filter => filter.toLowerCase() === key.toLowerCase())) {
|
||||||
|
filteredSchema.errors[key] = schema.errors[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredSchema
|
return filteredSchema
|
||||||
|
|
|
@ -18,6 +18,7 @@ import _ from "lodash"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { utils } from "@budibase/backend-core"
|
import { utils } from "@budibase/backend-core"
|
||||||
import { databaseTestProviders } from "../integrations/tests/utils"
|
import { databaseTestProviders } from "../integrations/tests/utils"
|
||||||
|
import { Client } from "pg"
|
||||||
|
|
||||||
const config = setup.getConfig()!
|
const config = setup.getConfig()!
|
||||||
|
|
||||||
|
@ -1055,4 +1056,53 @@ describe("postgres integrations", () => {
|
||||||
expect(response.body.tableNames.indexOf(primaryName)).not.toBe(-1)
|
expect(response.body.tableNames.indexOf(primaryName)).not.toBe(-1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("POST /api/datasources/:datasourceId/schema", () => {
|
||||||
|
let client: Client
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
client = new Client(
|
||||||
|
(await databaseTestProviders.postgres.getDsConfig()).config!
|
||||||
|
)
|
||||||
|
await client.connect()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await client.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("recognises when a table has no primary key", async () => {
|
||||||
|
await client.query(`
|
||||||
|
CREATE TABLE table_without_primary_key (
|
||||||
|
id SERIAL
|
||||||
|
)
|
||||||
|
`)
|
||||||
|
|
||||||
|
const response = await makeRequest(
|
||||||
|
"post",
|
||||||
|
`/api/datasources/${postgresDatasource._id}/schema`
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.body.errors).toMatchObject({
|
||||||
|
table_without_primary_key: "Table must have a primary key.",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("recognises when a table is using a reserved column name", async () => {
|
||||||
|
await client.query(`
|
||||||
|
CREATE TABLE table_with_reserved_column_name (
|
||||||
|
_id SERIAL
|
||||||
|
)
|
||||||
|
`)
|
||||||
|
|
||||||
|
const response = await makeRequest(
|
||||||
|
"post",
|
||||||
|
`/api/datasources/${postgresDatasource._id}/schema`
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.body.errors).toMatchObject({
|
||||||
|
table_without_primary_key: "Table must have a primary key.",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue