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