Ensure consistency
This commit is contained in:
parent
9bac192cf9
commit
041f85886c
|
@ -294,6 +294,7 @@ describe.each([
|
|||
readonly: true,
|
||||
},
|
||||
description: {
|
||||
visible: true,
|
||||
readonly: true,
|
||||
},
|
||||
},
|
||||
|
@ -306,6 +307,7 @@ describe.each([
|
|||
readonly: true,
|
||||
},
|
||||
description: {
|
||||
visible: true,
|
||||
readonly: true,
|
||||
},
|
||||
})
|
||||
|
@ -348,6 +350,42 @@ describe.each([
|
|||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("readonly fields must be visible", async () => {
|
||||
const table = await config.api.table.save(
|
||||
saveTableRequest({
|
||||
schema: {
|
||||
name: {
|
||||
name: "name",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
description: {
|
||||
name: "description",
|
||||
type: FieldType.STRING,
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
const newView: CreateViewRequest = {
|
||||
name: generator.name(),
|
||||
tableId: table._id!,
|
||||
schema: {
|
||||
name: {
|
||||
visible: false,
|
||||
readonly: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
await config.api.viewV2.create(newView, {
|
||||
status: 400,
|
||||
body: {
|
||||
message: 'Field "name" cannot be readonly and not visible',
|
||||
status: 400,
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
|
|
|
@ -52,14 +52,20 @@ async function guardViewSchema(
|
|||
)
|
||||
}
|
||||
|
||||
if (
|
||||
viewSchema[field].readonly &&
|
||||
isRequired(tableSchemaField.constraints)
|
||||
) {
|
||||
throw new HTTPError(
|
||||
`Field "${field}" cannot be readonly as it is a required field`,
|
||||
400
|
||||
)
|
||||
if (viewSchema[field].readonly) {
|
||||
if (isRequired(tableSchemaField.constraints)) {
|
||||
throw new HTTPError(
|
||||
`Field "${field}" cannot be readonly as it is a required field`,
|
||||
400
|
||||
)
|
||||
}
|
||||
|
||||
if (!viewSchema[field].visible) {
|
||||
throw new HTTPError(
|
||||
`Field "${field}" cannot be readonly and not visible`,
|
||||
400
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue