Prevent relation update from settings (#13099)

## Expected behavior

Described behavior regarding: (update | create) x (custom | standard) x
(icon, label, name, isSynced)

**Custom:**
- Field RELATION create: name, label, isSynced, icon should be editable
- Field RELATION update: name should not, icon label, isSynced should
- For other fields, icon, label, name, isSynced should be editable at
field creation | update

To simplify: Field RELATION name should not be editable at update

**Standards**
- Field: create does not makes sense
- Field: name should not, icon label, isSynced should (this will end up
in overrides)

To simplify, no Field RELATION edge case, name should not be editable at
update

**Note:** the FE logic is quite different as the UI is hiding some
details behind the syncWithLabel. See my comments and TODO there


## What I've tested:
(update | create) x (custom | standard) x (icon, label, name, isSynced,
description)
This commit is contained in:
Charles Bochet
2025-07-08 21:03:38 +02:00
committed by GitHub
parent c8ec44eeaf
commit 39f6f3c4bb
13 changed files with 615 additions and 150 deletions

View File

@ -1,66 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Field metadata relation creation should fail relation when targetFieldLabel conflicts with an existing field on target object metadata id 1`] = `
[
{
"extensions": {
"code": "BAD_USER_INPUT",
"userFriendlyMessage": "An error occurred.",
},
"message": "Name "collisionfieldlabel" is not available",
"name": "UserInputError",
},
]
`;
exports[`Field metadata relation creation should fail relation when targetFieldLabel contains only whitespace 1`] = `
[
{
"extensions": {
"code": "BAD_USER_INPUT",
"userFriendlyMessage": "An error occurred.",
},
"message": "Invalid label: " "",
"name": "UserInputError",
},
]
`;
exports[`Field metadata relation creation should fail relation when targetFieldLabel exceeds maximum length 1`] = `
[
{
"extensions": {
"code": "BAD_USER_INPUT",
"userFriendlyMessage": "An error occurred.",
},
"message": "Name is too long: it exceeds the 63 characters limit.",
"name": "UserInputError",
},
]
`;
exports[`Field metadata relation creation should fail relation when targetFieldLabel is empty 1`] = `
[
{
"extensions": {
"code": "BAD_USER_INPUT",
"userFriendlyMessage": "An error occurred.",
},
"message": "Input is too short: """,
"name": "UserInputError",
},
]
`;
exports[`Field metadata relation creation should fail relation when targetObjectMetadataId is unknown 1`] = `
[
{
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exceptionEventId": "mocked-exception-id",
"userFriendlyMessage": "An error occurred.",
},
"message": "Cannot read properties of undefined (reading 'fieldsById')",
},
]
`;

View File

@ -1,149 +0,0 @@
import { faker } from '@faker-js/faker/.';
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
import { getMockCreateObjectInput } from 'test/integration/metadata/suites/object-metadata/utils/generate-mock-create-object-metadata-input';
import { EachTestingContext } from 'twenty-shared/testing';
import { FieldMetadataType } from 'twenty-shared/types';
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
import { CreateFieldInput } from 'src/engine/metadata-modules/field-metadata/dtos/create-field.input';
type GlobalTestContext = {
objectMetadataIds: {
targetObjectId: string;
sourceObjectId: string;
};
collisionFieldLabel: string;
};
const globalTestContext: GlobalTestContext = {
objectMetadataIds: {
targetObjectId: '',
sourceObjectId: '',
},
collisionFieldLabel: 'collisionfieldlabel',
};
type TestedRelationCreationPayload = Partial<
NonNullable<CreateFieldInput['relationCreationPayload']>
>;
type CreateOneObjectMetadataItemTestingContext = EachTestingContext<
| TestedRelationCreationPayload
| ((context: GlobalTestContext) => TestedRelationCreationPayload)
>[];
describe('Field metadata relation creation should fail', () => {
const failingLabelsCreationTestsUseCase: CreateOneObjectMetadataItemTestingContext =
[
// TODO @prastoin add coverage other fields such as the Type, icon etc etc ( using edge cases fuzzing etc )
{
title: 'when targetFieldLabel is empty',
context: { targetFieldLabel: '' },
},
{
title: 'when targetFieldLabel exceeds maximum length',
context: { targetFieldLabel: 'A'.repeat(64) },
},
{
// Not handled gracefully should be refactored
title: 'when targetObjectMetadataId is unknown',
context: { targetObjectMetadataId: faker.string.uuid() },
},
{
title: 'when targetFieldLabel contains only whitespace',
context: { targetFieldLabel: ' ' },
},
{
title:
'when targetFieldLabel conflicts with an existing field on target object metadata id',
context: ({ collisionFieldLabel, objectMetadataIds }) => ({
targetObjectMetadataId: objectMetadataIds.targetObjectId,
targetFieldLabel: collisionFieldLabel,
}),
},
];
beforeAll(async () => {
const {
data: {
createOneObject: { id: sourceObjectId },
},
} = await createOneObjectMetadata({
input: getMockCreateObjectInput({
namePlural: 'collisionRelations',
nameSingular: 'collisionRelation',
}),
});
const {
data: {
createOneObject: { id: targetObjectId },
},
} = await createOneObjectMetadata({
input: getMockCreateObjectInput({
namePlural: 'collisionRelationTargets',
nameSingular: 'collisionRelationTarget',
}),
});
globalTestContext.objectMetadataIds = {
sourceObjectId,
targetObjectId,
};
const { data } = await createOneFieldMetadata({
input: {
objectMetadataId: targetObjectId,
name: globalTestContext.collisionFieldLabel,
label: 'LabelThatCouldBeAnything',
isLabelSyncedWithName: false,
type: FieldMetadataType.TEXT,
},
});
expect(data).toBeDefined();
});
afterAll(async () => {
for (const objectMetadataId of Object.values(
globalTestContext.objectMetadataIds,
)) {
await deleteOneObjectMetadata({
input: {
idToDelete: objectMetadataId,
},
});
}
});
it.each(failingLabelsCreationTestsUseCase)(
'relation $title',
async ({ context }) => {
const computedContext =
typeof context === 'function' ? context(globalTestContext) : context;
const { errors } = await createOneFieldMetadata({
expectToFail: true,
input: {
objectMetadataId: globalTestContext.objectMetadataIds.sourceObjectId,
name: 'fieldname',
label: 'Relation field',
isLabelSyncedWithName: false,
type: FieldMetadataType.RELATION,
relationCreationPayload: {
targetFieldLabel: 'defaultTargetFieldLabel',
type: RelationType.ONE_TO_MANY,
targetObjectMetadataId:
globalTestContext.objectMetadataIds.targetObjectId,
targetFieldIcon: 'IconBuildingSkyscraper',
...computedContext,
},
},
});
expect(errors).toBeDefined();
expect(errors).toMatchSnapshot();
},
);
});