4fbdfb6abc
## 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
212 lines
6.7 KiB
TypeScript
212 lines
6.7 KiB
TypeScript
import { UPDATE_ENUM_FIELD_METADATA_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/common/update-enum-field-metadata-test-cases';
|
|
import { type CreateOneFieldFactoryInput } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata-query-factory.util';
|
|
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
|
|
import { deleteOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/delete-one-field-metadata.util';
|
|
import { updateOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/update-one-field-metadata.util';
|
|
import { CUSTOM_OBJECT_DISHES } from 'test/integration/metadata/suites/object-metadata/constants/custom-object-dishes.constants';
|
|
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 { eachTestingContextFilter } from 'twenty-shared/testing';
|
|
import { FieldMetadataType } from 'twenty-shared/types';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { fieldMetadataEnumTypes } from 'src/engine/metadata-modules/field-metadata/utils/is-enum-field-metadata-type.util';
|
|
import {
|
|
type FieldMetadataComplexOption,
|
|
type FieldMetadataDefaultOption,
|
|
} from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
|
|
|
|
describe.each(fieldMetadataEnumTypes)(
|
|
'Successful update field metadata %s tests suite v2',
|
|
(testedFieldMetadataType) => {
|
|
let createdObjectMetadataId: string;
|
|
let createdFieldMetadataId: string;
|
|
const testCases =
|
|
UPDATE_ENUM_FIELD_METADATA_TEST_CASES[testedFieldMetadataType];
|
|
|
|
if (!isDefined(testCases)) {
|
|
return;
|
|
}
|
|
const { successful: successfulTestCases } = testCases;
|
|
const initialOptions: CreateOneFieldFactoryInput['options'] = [
|
|
{
|
|
label: 'Option 1',
|
|
value: 'OPTION_1',
|
|
color: 'green',
|
|
position: 1,
|
|
},
|
|
{
|
|
label: 'Option 2',
|
|
value: 'OPTION_2',
|
|
color: 'green',
|
|
position: 2,
|
|
},
|
|
];
|
|
|
|
beforeAll(async () => {
|
|
const {
|
|
labelPlural,
|
|
description,
|
|
labelSingular,
|
|
namePlural,
|
|
nameSingular,
|
|
} = CUSTOM_OBJECT_DISHES;
|
|
const { data } = await createOneObjectMetadata({
|
|
input: {
|
|
labelPlural,
|
|
description,
|
|
labelSingular,
|
|
namePlural,
|
|
nameSingular,
|
|
icon: 'IconBuildingSkyscraper',
|
|
isLabelSyncedWithName: false,
|
|
},
|
|
});
|
|
|
|
createdObjectMetadataId = data.createOneObject.id;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: createdObjectMetadataId,
|
|
updatePayload: { isActive: false },
|
|
},
|
|
});
|
|
await deleteOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: { idToDelete: createdObjectMetadataId },
|
|
});
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
const {
|
|
data: { createOneField },
|
|
} = await createOneFieldMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
objectMetadataId: createdObjectMetadataId,
|
|
type: testedFieldMetadataType,
|
|
name: 'testField',
|
|
label: 'Test Field',
|
|
isLabelSyncedWithName: false,
|
|
options: initialOptions,
|
|
},
|
|
gqlFields: `
|
|
id
|
|
type
|
|
`,
|
|
});
|
|
|
|
createdFieldMetadataId = createOneField.id;
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await updateOneFieldMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: createdFieldMetadataId,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
await deleteOneFieldMetadata({
|
|
expectToFail: false,
|
|
input: { idToDelete: createdFieldMetadataId },
|
|
});
|
|
});
|
|
|
|
it('Should update default value to null even if it was set before', async () => {
|
|
const isMultiSelect =
|
|
testedFieldMetadataType === FieldMetadataType.MULTI_SELECT;
|
|
const rawDefaultValue = `'${initialOptions[0].value}'`;
|
|
const expectedDefaultValue = isMultiSelect
|
|
? [rawDefaultValue]
|
|
: rawDefaultValue;
|
|
|
|
const { data: firstUpdate } = await updateOneFieldMetadata({
|
|
input: {
|
|
idToUpdate: createdFieldMetadataId,
|
|
updatePayload: {
|
|
defaultValue: expectedDefaultValue,
|
|
},
|
|
},
|
|
gqlFields: `
|
|
id
|
|
defaultValue
|
|
`,
|
|
});
|
|
|
|
expect(firstUpdate.updateOneField.defaultValue).toEqual(
|
|
expectedDefaultValue,
|
|
);
|
|
|
|
const updatedOptions = initialOptions.slice(1);
|
|
const { data: secondUpdate, errors } = await updateOneFieldMetadata({
|
|
input: {
|
|
idToUpdate: createdFieldMetadataId,
|
|
updatePayload: {
|
|
defaultValue: null,
|
|
options: updatedOptions,
|
|
},
|
|
},
|
|
gqlFields: `
|
|
id
|
|
options
|
|
defaultValue
|
|
`,
|
|
});
|
|
|
|
expect(errors).toBeUndefined();
|
|
expect(secondUpdate.updateOneField.defaultValue).toBeNull();
|
|
expect(secondUpdate.updateOneField.options).toMatchObject(updatedOptions);
|
|
});
|
|
|
|
test.each(eachTestingContextFilter(successfulTestCases))(
|
|
'Update $title',
|
|
async ({ context: { input, expectedOptions } }) => {
|
|
const { ...updatePayload } = input;
|
|
|
|
const { data, errors } = await updateOneFieldMetadata({
|
|
input: {
|
|
idToUpdate: createdFieldMetadataId,
|
|
updatePayload,
|
|
},
|
|
gqlFields: `
|
|
id
|
|
options
|
|
defaultValue
|
|
`,
|
|
});
|
|
|
|
expect(data.updateOneField).toBeDefined();
|
|
const updatedOptions:
|
|
| FieldMetadataComplexOption[]
|
|
| FieldMetadataDefaultOption[]
|
|
| null = data.updateOneField.options;
|
|
|
|
expect(updatedOptions).toBeDefined();
|
|
if (!isDefined(updatedOptions))
|
|
throw new Error(
|
|
'Should never occur, type invariant post test assertion',
|
|
);
|
|
|
|
expect(errors).toBeUndefined();
|
|
updatedOptions.forEach((option) => expect(option.id).toBeDefined());
|
|
|
|
const optionsToCompare = expectedOptions ?? input.options ?? [];
|
|
|
|
expect(updatedOptions.length).toBe(optionsToCompare.length);
|
|
expect(updatedOptions).toMatchObject(optionsToCompare);
|
|
|
|
if (isDefined(input.defaultValue)) {
|
|
expect(data.updateOneField.defaultValue).toEqual(input.defaultValue);
|
|
}
|
|
},
|
|
);
|
|
},
|
|
);
|