1
0
Fork 0
mirror of synced 2024-09-10 06:26:02 +12:00

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, readonly: true,
}, },
description: { description: {
visible: true,
readonly: true, readonly: true,
}, },
}, },
@ -306,6 +307,7 @@ describe.each([
readonly: true, readonly: true,
}, },
description: { description: {
visible: true,
readonly: 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", () => { describe("update", () => {

View file

@ -52,14 +52,20 @@ async function guardViewSchema(
) )
} }
if ( if (viewSchema[field].readonly) {
viewSchema[field].readonly && if (isRequired(tableSchemaField.constraints)) {
isRequired(tableSchemaField.constraints) throw new HTTPError(
) { `Field "${field}" cannot be readonly as it is a required field`,
throw new HTTPError( 400
`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
)
}
} }
} }
} }