Ensure consistency

This commit is contained in:
Adria Navarro 2024-05-27 14:16:03 +02:00
parent 9bac192cf9
commit 041f85886c
2 changed files with 52 additions and 8 deletions

View File

@ -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", () => {

View File

@ -52,15 +52,21 @@ async function guardViewSchema(
)
}
if (
viewSchema[field].readonly &&
isRequired(tableSchemaField.constraints)
) {
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
)
}
}
}
}
}