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