Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 3s
501 lines
16 KiB
TypeScript
501 lines
16 KiB
TypeScript
import { faker } from '@faker-js/faker';
|
|
import { expectOneNotInternalServerErrorSnapshot } from 'test/integration/graphql/utils/expect-one-not-internal-server-error-snapshot.util';
|
|
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 { 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 {
|
|
eachTestingContextFilter,
|
|
type 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 { type CreateFieldInput } from 'src/engine/metadata-modules/field-metadata/dtos/create-field.input';
|
|
|
|
type GlobalTestContext = {
|
|
objectMetadataIds: {
|
|
targetObjectId: string;
|
|
sourceObjectId: string;
|
|
};
|
|
collisionFieldName: string;
|
|
collisionFieldNameWithId: string;
|
|
collisionFieldLabel: string;
|
|
collisionFieldLabelWithId: string;
|
|
};
|
|
const globalTestContext: GlobalTestContext = {
|
|
objectMetadataIds: {
|
|
targetObjectId: '',
|
|
sourceObjectId: '',
|
|
},
|
|
collisionFieldLabel: 'Field Name',
|
|
collisionFieldName: 'fieldName',
|
|
collisionFieldNameWithId: 'fieldNameBisId',
|
|
collisionFieldLabelWithId: 'Field Name Bis Id',
|
|
};
|
|
|
|
type TestedRelationCreationPayload = Partial<
|
|
NonNullable<CreateFieldInput['relationCreationPayload']>
|
|
>;
|
|
|
|
type TestedContext = {
|
|
input: {
|
|
name?: string;
|
|
relationCreationPayload?: TestedRelationCreationPayload;
|
|
};
|
|
};
|
|
|
|
type CreateOneObjectMetadataItemTestingContext = EachTestingContext<
|
|
TestedContext | ((context: GlobalTestContext) => TestedContext)
|
|
>[];
|
|
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: '(relationCreationPayload) when targetFieldLabel is empty',
|
|
context: {
|
|
input: { relationCreationPayload: { targetFieldLabel: '' } },
|
|
},
|
|
},
|
|
{
|
|
title:
|
|
'(relationCreationPayload) when targetFieldLabel exceeds maximum length',
|
|
context: {
|
|
input: {
|
|
relationCreationPayload: { targetFieldLabel: 'A'.repeat(64) },
|
|
},
|
|
},
|
|
},
|
|
{
|
|
// Not handled gracefully should be refactored
|
|
title:
|
|
'(relationCreationPayload) when targetObjectMetadataId is unknown',
|
|
context: {
|
|
input: {
|
|
relationCreationPayload: {
|
|
targetObjectMetadataId: faker.string.uuid(),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
title:
|
|
'(relationCreationPayload) when targetFieldLabel contains only whitespace',
|
|
context: {
|
|
input: {
|
|
relationCreationPayload: { targetFieldLabel: ' ' },
|
|
},
|
|
},
|
|
},
|
|
{
|
|
title:
|
|
'(relationCreationPayload) when targetFieldLabel conflicts with an existing field on target object metadata id',
|
|
context: ({ collisionFieldLabel, objectMetadataIds }) => ({
|
|
input: {
|
|
relationCreationPayload: {
|
|
targetObjectMetadataId: objectMetadataIds.targetObjectId,
|
|
targetFieldLabel: collisionFieldLabel,
|
|
},
|
|
},
|
|
}),
|
|
},
|
|
{
|
|
title:
|
|
'(relationCreationPayload) when targetFieldLabel conflicts with an existing {name}Id on target object metadata id',
|
|
context: ({ collisionFieldLabelWithId, objectMetadataIds }) => ({
|
|
input: {
|
|
relationCreationPayload: {
|
|
targetObjectMetadataId: objectMetadataIds.targetObjectId,
|
|
targetFieldLabel: collisionFieldLabelWithId,
|
|
},
|
|
},
|
|
}),
|
|
},
|
|
{
|
|
title: '(relationCreationPayload) when type is not provided',
|
|
context: {
|
|
input: {
|
|
relationCreationPayload: { type: undefined },
|
|
},
|
|
},
|
|
},
|
|
{
|
|
title: '(relationCreationPayload) when type is a wrong value',
|
|
context: {
|
|
input: {
|
|
relationCreationPayload: { type: 'wrong' as RelationType },
|
|
},
|
|
},
|
|
},
|
|
{
|
|
title: 'when {name}Id is already used',
|
|
context: ({ collisionFieldNameWithId }) => ({
|
|
input: {
|
|
name: collisionFieldNameWithId,
|
|
relationCreationPayload: { targetFieldIcon: '' },
|
|
},
|
|
}),
|
|
},
|
|
{
|
|
title:
|
|
'when target and source are the same object and name are the same',
|
|
context: {
|
|
input: {
|
|
name: 'relationName',
|
|
relationCreationPayload: {
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.sourceObjectId,
|
|
targetFieldLabel: 'Relation Name',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
title:
|
|
'(relationCreationPayload) when targetObjectMetadataId is not a valid uuid format',
|
|
context: {
|
|
input: {
|
|
relationCreationPayload: {
|
|
targetObjectMetadataId: 'not-a-valid-uuid',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
title: 'when source field name conflicts with existing field name',
|
|
context: ({ collisionFieldName }) => ({
|
|
input: {
|
|
name: collisionFieldName,
|
|
relationCreationPayload: {
|
|
targetFieldLabel: 'Unique Target Label',
|
|
},
|
|
},
|
|
}),
|
|
},
|
|
{
|
|
title:
|
|
'when self-relation source field join column would conflict with target field name',
|
|
context: {
|
|
input: {
|
|
name: 'parent',
|
|
relationCreationPayload: {
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.sourceObjectId,
|
|
targetFieldLabel: 'Parent Id',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
title:
|
|
'when self-relation target join column would conflict with source field name',
|
|
context: {
|
|
input: {
|
|
name: 'childrenId',
|
|
relationCreationPayload: {
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.sourceObjectId,
|
|
targetFieldLabel: 'Children',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
];
|
|
|
|
beforeAll(async () => {
|
|
const {
|
|
data: {
|
|
createOneObject: { id: sourceObjectId },
|
|
},
|
|
} = await createOneObjectMetadata({
|
|
input: getMockCreateObjectInput({
|
|
namePlural: 'sourceObjects',
|
|
nameSingular: 'sourceObject',
|
|
}),
|
|
});
|
|
|
|
const {
|
|
data: {
|
|
createOneObject: { id: targetObjectId },
|
|
},
|
|
} = await createOneObjectMetadata({
|
|
input: getMockCreateObjectInput({
|
|
namePlural: 'targetObjects',
|
|
nameSingular: 'targetObject',
|
|
}),
|
|
});
|
|
|
|
globalTestContext.objectMetadataIds = {
|
|
sourceObjectId,
|
|
targetObjectId,
|
|
};
|
|
|
|
const { data: collisionFieldWithLabelTargetData } =
|
|
await createOneFieldMetadata({
|
|
input: {
|
|
objectMetadataId: targetObjectId,
|
|
name: globalTestContext.collisionFieldName,
|
|
label: 'LabelThatCouldBeAnything',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.TEXT,
|
|
},
|
|
});
|
|
|
|
const { data: collisionFieldWithIdTargetData } =
|
|
await createOneFieldMetadata({
|
|
input: {
|
|
objectMetadataId: targetObjectId,
|
|
name: globalTestContext.collisionFieldNameWithId,
|
|
label: 'LabelThatCouldBeAnything',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.TEXT,
|
|
},
|
|
});
|
|
|
|
const { data: collisionFieldWithLabelSourceData } =
|
|
await createOneFieldMetadata({
|
|
input: {
|
|
objectMetadataId: sourceObjectId,
|
|
name: globalTestContext.collisionFieldName,
|
|
label: 'LabelThatCouldBeAnything',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.TEXT,
|
|
},
|
|
});
|
|
|
|
const { data: collisionFieldWithIdSourceData } =
|
|
await createOneFieldMetadata({
|
|
input: {
|
|
objectMetadataId: sourceObjectId,
|
|
name: globalTestContext.collisionFieldNameWithId,
|
|
label: 'LabelThatCouldBeAnything',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.TEXT,
|
|
},
|
|
});
|
|
|
|
expect(collisionFieldWithLabelTargetData).toBeDefined();
|
|
expect(collisionFieldWithIdTargetData).toBeDefined();
|
|
expect(collisionFieldWithLabelSourceData).toBeDefined();
|
|
expect(collisionFieldWithIdSourceData).toBeDefined();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
for (const objectMetadataId of Object.values(
|
|
globalTestContext.objectMetadataIds,
|
|
)) {
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: objectMetadataId,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
await deleteOneObjectMetadata({
|
|
input: {
|
|
idToDelete: objectMetadataId,
|
|
},
|
|
});
|
|
}
|
|
});
|
|
|
|
it.each(eachTestingContextFilter(failingLabelsCreationTestsUseCase))(
|
|
'relation ONE_TO_MANY $title',
|
|
async ({ context }) => {
|
|
const computedRelationCreationPayload =
|
|
typeof context === 'function'
|
|
? context(globalTestContext).input.relationCreationPayload
|
|
: context.input.relationCreationPayload;
|
|
|
|
const computedName =
|
|
typeof context === 'function'
|
|
? context(globalTestContext).input.name
|
|
: context.input.name;
|
|
|
|
const { errors } = await createOneFieldMetadata({
|
|
expectToFail: true,
|
|
input: {
|
|
objectMetadataId: globalTestContext.objectMetadataIds.sourceObjectId,
|
|
name: computedName ?? 'fieldname',
|
|
label: 'Relation field',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.RELATION,
|
|
relationCreationPayload: {
|
|
targetFieldLabel: 'defaultTargetFieldLabel',
|
|
type: RelationType.ONE_TO_MANY,
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.targetObjectId,
|
|
targetFieldIcon: 'IconBuildingSkyscraper',
|
|
...computedRelationCreationPayload,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(errors).toBeDefined();
|
|
expect(errors).toMatchSnapshot(
|
|
extractRecordIdsAndDatesAsExpectAny(errors),
|
|
);
|
|
},
|
|
);
|
|
|
|
it.each(eachTestingContextFilter(failingLabelsCreationTestsUseCase))(
|
|
'relation MANY_TO_ONE $title',
|
|
async ({ context }) => {
|
|
const computedRelationCreationPayload =
|
|
typeof context === 'function'
|
|
? context(globalTestContext).input.relationCreationPayload
|
|
: context.input.relationCreationPayload;
|
|
|
|
const computedName =
|
|
typeof context === 'function'
|
|
? context(globalTestContext).input.name
|
|
: context.input.name;
|
|
|
|
const { errors } = await createOneFieldMetadata({
|
|
expectToFail: true,
|
|
input: {
|
|
objectMetadataId: globalTestContext.objectMetadataIds.sourceObjectId,
|
|
name: computedName ?? 'fieldname',
|
|
label: 'Relation field',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.RELATION,
|
|
relationCreationPayload: {
|
|
targetFieldLabel: 'defaultTargetFieldLabel',
|
|
type: RelationType.MANY_TO_ONE,
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.targetObjectId,
|
|
targetFieldIcon: 'IconBuildingSkyscraper',
|
|
...computedRelationCreationPayload,
|
|
},
|
|
},
|
|
});
|
|
|
|
expectOneNotInternalServerErrorSnapshot({
|
|
errors,
|
|
});
|
|
},
|
|
);
|
|
|
|
it('should fail when creating MANY_TO_ONE self-relation with same field name and label', async () => {
|
|
const { errors } = await createOneFieldMetadata({
|
|
expectToFail: true,
|
|
input: {
|
|
objectMetadataId: globalTestContext.objectMetadataIds.sourceObjectId,
|
|
name: 'manager',
|
|
label: 'Manager',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.RELATION,
|
|
relationCreationPayload: {
|
|
targetFieldLabel: 'Manager',
|
|
type: RelationType.MANY_TO_ONE,
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.sourceObjectId,
|
|
targetFieldIcon: 'IconUser',
|
|
},
|
|
},
|
|
});
|
|
|
|
expectOneNotInternalServerErrorSnapshot({
|
|
errors,
|
|
});
|
|
});
|
|
|
|
it('should fail when creating ONE_TO_MANY self-relation with same field name and label', async () => {
|
|
const { errors } = await createOneFieldMetadata({
|
|
expectToFail: true,
|
|
input: {
|
|
objectMetadataId: globalTestContext.objectMetadataIds.sourceObjectId,
|
|
name: 'manager',
|
|
label: 'Manager',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.RELATION,
|
|
relationCreationPayload: {
|
|
targetFieldLabel: 'Manager',
|
|
type: RelationType.ONE_TO_MANY,
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.sourceObjectId,
|
|
targetFieldIcon: 'IconUser',
|
|
},
|
|
},
|
|
});
|
|
|
|
expectOneNotInternalServerErrorSnapshot({
|
|
errors,
|
|
});
|
|
});
|
|
|
|
it('should fail when creating a relation field with name that conflicts with existing field name', async () => {
|
|
const { errors } = await createOneFieldMetadata({
|
|
expectToFail: true,
|
|
input: {
|
|
objectMetadataId: globalTestContext.objectMetadataIds.sourceObjectId,
|
|
name: globalTestContext.collisionFieldName,
|
|
label: 'Duplicate Field',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.RELATION,
|
|
relationCreationPayload: {
|
|
targetFieldLabel: 'Related Object',
|
|
type: RelationType.MANY_TO_ONE,
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.targetObjectId,
|
|
targetFieldIcon: 'IconLink',
|
|
},
|
|
},
|
|
});
|
|
|
|
expectOneNotInternalServerErrorSnapshot({
|
|
errors,
|
|
});
|
|
});
|
|
|
|
it('should fail when creating a relation field with name that conflicts with existing join column name', async () => {
|
|
const relationFieldName = 'company';
|
|
|
|
await createOneFieldMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
objectMetadataId: globalTestContext.objectMetadataIds.sourceObjectId,
|
|
name: relationFieldName,
|
|
label: 'Company',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.RELATION,
|
|
relationCreationPayload: {
|
|
targetFieldLabel: 'company',
|
|
type: RelationType.MANY_TO_ONE,
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.targetObjectId,
|
|
targetFieldIcon: 'IconBuilding',
|
|
},
|
|
},
|
|
});
|
|
|
|
const { errors } = await createOneFieldMetadata({
|
|
expectToFail: true,
|
|
input: {
|
|
objectMetadataId: globalTestContext.objectMetadataIds.sourceObjectId,
|
|
name: `${relationFieldName}Id`,
|
|
label: 'Company Id Field',
|
|
isLabelSyncedWithName: false,
|
|
type: FieldMetadataType.RELATION,
|
|
relationCreationPayload: {
|
|
targetFieldLabel: 'Related',
|
|
type: RelationType.MANY_TO_ONE,
|
|
targetObjectMetadataId:
|
|
globalTestContext.objectMetadataIds.targetObjectId,
|
|
targetFieldIcon: 'IconLink',
|
|
},
|
|
},
|
|
});
|
|
|
|
expectOneNotInternalServerErrorSnapshot({
|
|
errors,
|
|
});
|
|
});
|
|
});
|