Files
twenty/packages/twenty-server/test/integration/metadata/suites/field-metadata/update-one-field-metadata.integration-spec.ts
T
Paul Rastoin 4fbdfb6abc Activate v2 default seed (#14660)
## Introduction
After enabling flag by default got following errors:
```ts
Test Suites: 48 failed, 1 skipped, 97 passed, 145 of 146 total
Tests:       499 failed, 1 skipped, 644 passed, 1144 total
Snapshots:   61 failed, 133 passed, 194 total
Time:        363.226 s
Ran all test suites.
```

## From
<img width="2952" height="1510" alt="image"
src="https://github.com/user-attachments/assets/7e3b20c6-2552-40a7-90bb-2d7b3002c895"
/>

## To
<img width="3134" height="1510" alt="image"
src="https://github.com/user-attachments/assets/4fc9ada4-3c14-4333-a1db-11daf87db8d6"
/>

There's a huge test bundle in the latest shard that we could split up

## Notes
- Set as failing morph relation field rename as for the moment we do not
handle relation field mutation
- fixed the object update and creation validation adding label
identifier field metadata id checks
- and more

Some integrations tests are still on the v1 ( they have before and after
all disabling and re-enabling the flat ) but mainly we now have more
coverage on the v2 than the v1.
Mainly related records, uniqueness have to be migrated the v2 and so
tests too
2025-09-26 16:05:09 +02:00

206 lines
6.1 KiB
TypeScript

import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
import { updateOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/update-one-field-metadata.util';
import {
LISTING_NAME_PLURAL,
LISTING_NAME_SINGULAR,
} from 'test/integration/metadata/suites/object-metadata/constants/test-object-names.constant';
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 { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
import { extractRecordIdsAndDatesAsExpectAny } from 'test/utils/extract-record-ids-and-dates-as-expect-any';
import { FieldMetadataType } from 'twenty-shared/types';
describe('updateOne', () => {
describe('successful fieldMetadataService name/label sync', () => {
let listingObjectId = '';
let testFieldId = '';
beforeEach(async () => {
const { data } = await createOneObjectMetadata({
expectToFail: false,
input: {
labelSingular: LISTING_NAME_SINGULAR,
labelPlural: LISTING_NAME_PLURAL,
nameSingular: LISTING_NAME_SINGULAR,
namePlural: LISTING_NAME_PLURAL,
icon: 'IconBuildingSkyscraper',
isLabelSyncedWithName: true,
},
});
listingObjectId = data.createOneObject.id;
const { data: createdFieldMetadata } = await createOneFieldMetadata({
expectToFail: false,
input: {
objectMetadataId: listingObjectId,
type: FieldMetadataType.TEXT,
name: 'testName',
label: 'Test name',
isLabelSyncedWithName: true,
},
});
testFieldId = createdFieldMetadata.createOneField.id;
});
afterEach(async () => {
await updateOneObjectMetadata({
expectToFail: false,
input: {
idToUpdate: listingObjectId,
updatePayload: {
isActive: false,
},
},
});
await deleteOneObjectMetadata({
expectToFail: false,
input: { idToDelete: listingObjectId },
});
});
it('should update a field name and label when they are synced correctly', async () => {
// Arrange
const updateFieldInput = {
name: 'newName',
label: 'New name',
isLabelSyncedWithName: true,
};
// Act
const { data } = await updateOneFieldMetadata({
input: { idToUpdate: testFieldId, updatePayload: updateFieldInput },
gqlFields: `
id
name
label
isLabelSyncedWithName
`,
});
// Assert
expect(data.updateOneField.name).toBe('newName');
});
it('should update a field name and label when they are not synced correctly and labelSync is false', async () => {
// Arrange
const updateFieldInput = {
name: 'differentName',
label: 'New name',
isLabelSyncedWithName: false,
};
// Act
const { data } = await updateOneFieldMetadata({
input: { idToUpdate: testFieldId, updatePayload: updateFieldInput },
gqlFields: `
id
name
label
isLabelSyncedWithName
`,
});
// Assert
expect(data.updateOneField.name).toBe('differentName');
});
});
describe('failing update', () => {
let listingObjectId = '';
let testFieldId = '';
beforeAll(async () => {
const { data } = await createOneObjectMetadata({
expectToFail: false,
input: {
labelSingular: LISTING_NAME_SINGULAR,
labelPlural: LISTING_NAME_PLURAL,
nameSingular: LISTING_NAME_SINGULAR,
namePlural: LISTING_NAME_PLURAL,
icon: 'IconBuildingSkyscraper',
isLabelSyncedWithName: true,
},
});
listingObjectId = data.createOneObject.id;
const { data: createdFieldMetadata } = await createOneFieldMetadata({
expectToFail: false,
input: {
objectMetadataId: listingObjectId,
type: FieldMetadataType.TEXT,
name: 'testName',
label: 'Test name',
isLabelSyncedWithName: true,
},
});
testFieldId = createdFieldMetadata.createOneField.id;
});
afterAll(async () => {
await updateOneObjectMetadata({
expectToFail: false,
input: {
idToUpdate: listingObjectId,
updatePayload: {
isActive: false,
},
},
});
await deleteOneObjectMetadata({
expectToFail: false,
input: { idToDelete: listingObjectId },
});
});
it('should not update a field name if it is not synced correctly with label and labelSync is true', async () => {
// Arrange
const updateFieldInput = {
name: 'newName',
isLabelSyncedWithName: true,
};
// Act
const { errors } = await updateOneFieldMetadata({
input: { idToUpdate: testFieldId, updatePayload: updateFieldInput },
gqlFields: `
id
name
label
isLabelSyncedWithName
`,
expectToFail: true,
});
expect(errors).toMatchSnapshot(
extractRecordIdsAndDatesAsExpectAny(errors),
);
});
it('should throw if the field name is not available because of other field with the same name', async () => {
await createOneFieldMetadata({
expectToFail: false,
input: {
objectMetadataId: listingObjectId,
type: FieldMetadataType.TEXT,
name: 'otherTestName',
label: 'Test name',
},
});
const { errors } = await updateOneFieldMetadata({
expectToFail: true,
input: {
idToUpdate: testFieldId,
updatePayload: { name: 'otherTestName' },
},
});
expect(errors).toMatchSnapshot(
extractRecordIdsAndDatesAsExpectAny(errors),
);
});
});
});