Validate you can't group by complex fields.
This commit is contained in:
parent
f1b04d1252
commit
5c3adbed27
|
@ -25,8 +25,8 @@ import {
|
||||||
BBReferenceFieldSubType,
|
BBReferenceFieldSubType,
|
||||||
NumericCalculationFieldMetadata,
|
NumericCalculationFieldMetadata,
|
||||||
ViewV2Schema,
|
ViewV2Schema,
|
||||||
canGroupBy,
|
|
||||||
ViewV2Type,
|
ViewV2Type,
|
||||||
|
JsonTypes,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generator, mocks } from "@budibase/backend-core/tests"
|
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||||
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
||||||
|
@ -738,33 +738,33 @@ describe.each([
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it.only("cannot use complex types as group-by fields", async () => {
|
// We don't allow the creation of tables with most JsonTypes when using
|
||||||
const complexTypes = Object.values(FieldType).filter(
|
// external datasources.
|
||||||
type => !canGroupBy(type)
|
isInternal &&
|
||||||
)
|
it("cannot use complex types as group-by fields", async () => {
|
||||||
for (const type of complexTypes) {
|
for (const type of JsonTypes) {
|
||||||
const field = { name: "field", type } as FieldSchema
|
const field = { name: "field", type } as FieldSchema
|
||||||
const table = await config.api.table.save(
|
const table = await config.api.table.save(
|
||||||
saveTableRequest({ schema: { field } })
|
saveTableRequest({ schema: { field } })
|
||||||
)
|
)
|
||||||
await config.api.viewV2.create(
|
await config.api.viewV2.create(
|
||||||
{
|
{
|
||||||
tableId: table._id!,
|
tableId: table._id!,
|
||||||
name: generator.guid(),
|
name: generator.guid(),
|
||||||
type: ViewV2Type.CALCULATION,
|
type: ViewV2Type.CALCULATION,
|
||||||
schema: {
|
schema: {
|
||||||
field: { visible: true },
|
field: { visible: true },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
status: 400,
|
||||||
status: 400,
|
body: {
|
||||||
body: {
|
message: `Grouping by fields of type "${type}" is not supported`,
|
||||||
message: "",
|
},
|
||||||
},
|
}
|
||||||
}
|
)
|
||||||
)
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {
|
import {
|
||||||
CalculationType,
|
CalculationType,
|
||||||
|
canGroupBy,
|
||||||
FieldType,
|
FieldType,
|
||||||
isNumeric,
|
isNumeric,
|
||||||
PermissionLevel,
|
PermissionLevel,
|
||||||
|
@ -121,6 +122,13 @@ async function guardCalculationViewSchema(
|
||||||
400
|
400
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!canGroupBy(targetSchema.type)) {
|
||||||
|
throw new HTTPError(
|
||||||
|
`Grouping by fields of type "${targetSchema.type}" is not supported`,
|
||||||
|
400
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue