Validate you can't group by complex fields.

This commit is contained in:
Sam Rose 2024-10-08 15:34:34 +01:00
parent f1b04d1252
commit 5c3adbed27
No known key found for this signature in database
2 changed files with 35 additions and 27 deletions

View File

@ -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,11 +738,11 @@ 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 } })
@ -759,7 +759,7 @@ describe.each([
{ {
status: 400, status: 400,
body: { body: {
message: "", message: `Grouping by fields of type "${type}" is not supported`,
}, },
} }
) )

View File

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