Convert table.spec.ts to datasourceDescribe

This commit is contained in:
Sam Rose 2024-11-06 15:36:30 +00:00
parent c1d62224a8
commit 26aaac1d06
No known key found for this signature in database
1 changed files with 1302 additions and 1302 deletions

View File

@ -28,32 +28,24 @@ import * as setup from "./utilities"
import * as uuid from "uuid"
import { generator } from "@budibase/backend-core/tests"
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
import {
DatabaseName,
datasourceDescribe,
} from "../../../integrations/tests/utils"
import { tableForDatasource } from "../../../tests/utilities/structures"
import timekeeper from "timekeeper"
const { basicTable } = setup.structures
const ISO_REGEX_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
describe.each([
["sqs", undefined],
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
[DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)],
])("/tables (%s)", (name, dsProvider) => {
const isInternal: boolean = !dsProvider
datasourceDescribe(
{ name: "/tables (%s)", exclude: [DatabaseName.MONGODB] },
({ config, dsProvider, isInternal, isOracle }) => {
let datasource: Datasource | undefined
let config = setup.getConfig()
afterAll(setup.afterAll)
beforeAll(async () => {
await config.init()
if (dsProvider) {
datasource = await config.api.datasource.create(await dsProvider)
}
const ds = await dsProvider
datasource = ds.datasource
})
describe("create", () => {
@ -69,7 +61,7 @@ describe.each([
"with `backticks`",
]
if (name !== DatabaseName.ORACLE) {
if (!isOracle) {
names.push(`with "double quotes"`)
names.push(`with 'single quotes'`)
}
@ -229,12 +221,10 @@ describe.each([
}
// check base permissions
const { permissions: basePermissions } = await config.api.permission.get(
table._id!,
{
const { permissions: basePermissions } =
await config.api.permission.get(table._id!, {
status: 200,
}
)
})
const basePerms = { role: "BASIC", permissionType: "BASE" }
expect(basePermissions.write).toEqual(basePerms)
expect(basePermissions.read).toEqual(basePerms)
@ -1147,7 +1137,10 @@ describe.each([
})
describe.each([
[RowExportFormat.CSV, (val: any) => JSON.stringify(val).replace(/"/g, "'")],
[
RowExportFormat.CSV,
(val: any) => JSON.stringify(val).replace(/"/g, "'"),
],
[RowExportFormat.JSON, (val: any) => val],
])("import validation (%s)", (_, userParser) => {
const basicSchema: TableSchema = {
@ -1163,7 +1156,10 @@ describe.each([
const importCases: [
string,
(rows: Row[], schema: TableSchema) => Promise<ValidateTableImportResponse>
(
rows: Row[],
schema: TableSchema
) => Promise<ValidateTableImportResponse>
][] = [
[
"validateNewTableImport",
@ -1272,7 +1268,9 @@ describe.each([
isInternal &&
it.each(
isInternal ? PROTECTED_INTERNAL_COLUMNS : PROTECTED_EXTERNAL_COLUMNS
)("don't allow protected names in the rows (%s)", async columnName => {
)(
"don't allow protected names in the rows (%s)",
async columnName => {
const result = await config.api.table.validateNewTableImport({
rows: [
{
@ -1301,7 +1299,8 @@ describe.each([
[columnName]: false,
},
})
})
}
)
it("validates required fields and valid rows", async () => {
const schema: TableSchema = {
@ -1512,4 +1511,5 @@ describe.each([
})
})
})
})
}
)