47b60bd49f
# Introduction
From the moment replaced the FieldMetadataInterface definition to:
```ts
import { FieldMetadataType } from 'twenty-shared/types';
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
export type FieldMetadataInterface<
T extends FieldMetadataType = FieldMetadataType,
> = FieldMetadataEntity<T>;
```
After this PR merge will create a new one removing the type and
replacing it to `FieldMetadataEntity`.
Did not renamed it here to avoid conflicts on naming + type issues fixs
within the same PR
## Field metadata entity RELATION or MORPH
Relations fields cannot be null for those field metadata entity instance
anymore, but are never for the others see
`packages/twenty-server/src/engine/metadata-modules/field-metadata/types/field-metadata-entity-test.type.ts`
( introduced TypeScript tests )
## Concerns
- TS_VECTOR is the most at risk with the `generatedType` and
`asExpression` removal from interface
## What's next
- `FielMetadataInterface` removal and rename ( see introduction )
- Depcrecating `ObjectMetadataInterface`
- Refactor `FieldMetadataEntity` optional fiels to be nullable only
- TO DIG `never` occurences on settings, defaultValue etc
- Some interfaces will be replaced by the `FlatFieldMetadata` when
deprecating the current sync and comparators tools
113 lines
3.7 KiB
TypeScript
113 lines
3.7 KiB
TypeScript
import { CREATE_ENUM_FIELD_METADATA_TEST_CASES } from 'test/integration/metadata/suites/field-metadata/enum/create-enum-field-metadata-test-cases';
|
|
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
|
|
import {
|
|
LISTING_NAME_PLURAL,
|
|
LISTING_NAME_SINGULAR,
|
|
} from 'test/integration/metadata/suites/object-metadata/constants/test-object-names.constant';
|
|
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
|
import { forceCreateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/force-create-one-object-metadata.util';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { fieldMetadataEnumTypes } from 'src/engine/metadata-modules/field-metadata/utils/is-enum-field-metadata-type.util';
|
|
|
|
describe.each(fieldMetadataEnumTypes)(
|
|
'Create field metadata %s tests suite',
|
|
(testedFieldMetadataType) => {
|
|
let createdObjectMetadataId: string;
|
|
const testCases =
|
|
CREATE_ENUM_FIELD_METADATA_TEST_CASES[testedFieldMetadataType];
|
|
|
|
if (!isDefined(testCases)) {
|
|
return;
|
|
}
|
|
const { failing: failingTestCases, successful: successfulTestCases } =
|
|
testCases;
|
|
|
|
beforeEach(async () => {
|
|
const { data } = await forceCreateOneObjectMetadata({
|
|
input: {
|
|
labelSingular: LISTING_NAME_SINGULAR,
|
|
labelPlural: LISTING_NAME_PLURAL,
|
|
nameSingular: LISTING_NAME_SINGULAR,
|
|
namePlural: LISTING_NAME_PLURAL,
|
|
icon: 'IconBuildingSkyscraper',
|
|
isLabelSyncedWithName: false,
|
|
},
|
|
});
|
|
|
|
createdObjectMetadataId = data.createOneObject.id;
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await deleteOneObjectMetadata({
|
|
input: { idToDelete: createdObjectMetadataId },
|
|
});
|
|
});
|
|
|
|
test.each(successfulTestCases)(
|
|
'Create $title',
|
|
async ({ context: { input, expectedOptions } }) => {
|
|
const { data, errors } = await createOneFieldMetadata<
|
|
typeof testedFieldMetadataType
|
|
>({
|
|
input: {
|
|
objectMetadataId: createdObjectMetadataId,
|
|
type: testedFieldMetadataType,
|
|
name: 'testField',
|
|
label: 'Test Field',
|
|
isLabelSyncedWithName: false,
|
|
...input,
|
|
},
|
|
gqlFields: `
|
|
id
|
|
options
|
|
defaultValue
|
|
type
|
|
`,
|
|
});
|
|
|
|
expect(data).not.toBeNull();
|
|
expect(data.createOneField).toBeDefined();
|
|
expect(data.createOneField.type).toEqual(testedFieldMetadataType);
|
|
|
|
const createdOptions = data.createOneField.options;
|
|
const optionsToCompare = expectedOptions ?? input.options ?? [];
|
|
|
|
expect(errors).toBeUndefined();
|
|
expect(createdOptions?.length).toBe(optionsToCompare.length);
|
|
createdOptions?.forEach((option) => expect(option.id).toBeDefined());
|
|
expect(createdOptions).toMatchObject(optionsToCompare);
|
|
|
|
if (isDefined(input.defaultValue)) {
|
|
expect(data.createOneField.defaultValue).toEqual(input.defaultValue);
|
|
}
|
|
},
|
|
);
|
|
|
|
test.each(failingTestCases)(
|
|
'Create $title',
|
|
async ({ context: { input } }) => {
|
|
const { data, errors } = await createOneFieldMetadata({
|
|
input: {
|
|
objectMetadataId: createdObjectMetadataId,
|
|
type: testedFieldMetadataType,
|
|
name: 'testField',
|
|
label: 'Test Field',
|
|
isLabelSyncedWithName: false,
|
|
...input,
|
|
},
|
|
gqlFields: `
|
|
id
|
|
options
|
|
defaultValue
|
|
`,
|
|
});
|
|
|
|
expect(data).toBeNull();
|
|
expect(errors).toBeDefined();
|
|
expect(errors).toMatchSnapshot();
|
|
},
|
|
);
|
|
},
|
|
);
|