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
227 lines
7.1 KiB
TypeScript
227 lines
7.1 KiB
TypeScript
import { findManyFieldsMetadataQueryFactory } from 'test/integration/metadata/suites/field-metadata/utils/find-many-fields-metadata-query-factory.util';
|
|
import { createRelationBetweenObjects } from 'test/integration/metadata/suites/object-metadata/utils/create-relation-between-objects.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 { makeMetadataAPIRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';
|
|
import { type EachTestingContext } from 'twenty-shared/testing';
|
|
import { FieldMetadataType } from 'twenty-shared/types';
|
|
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
|
|
import { jestExpectToBeDefined } from 'test/utils/expect-to-be-defined.util.test';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
|
|
|
|
import { type FieldMetadataDTO } from 'src/engine/metadata-modules/field-metadata/dtos/field-metadata.dto';
|
|
import { type RelationDTO } from 'src/engine/metadata-modules/field-metadata/dtos/relation.dto';
|
|
|
|
type DeleteOneObjectMetadataItemTestingContext = EachTestingContext<
|
|
(args: { objectMetadataIdToDelete: string; relationFieldId: string }) => {
|
|
objectMetadataIdToDelete: string;
|
|
relationFieldId: string;
|
|
}
|
|
>[];
|
|
const successfulDeleteSourceUseCase: DeleteOneObjectMetadataItemTestingContext =
|
|
[
|
|
{
|
|
title:
|
|
'When deleting source object, the relation on the target should be deleted',
|
|
context: ({ objectMetadataIdToDelete, relationFieldId }) => ({
|
|
objectMetadataIdToDelete,
|
|
relationFieldId,
|
|
}),
|
|
},
|
|
];
|
|
|
|
const successfulDeleteTargetUseCase: DeleteOneObjectMetadataItemTestingContext =
|
|
[
|
|
{
|
|
title:
|
|
'When deleting target object, the relation on the source should be deleted',
|
|
context: ({ objectMetadataIdToDelete, relationFieldId }) => ({
|
|
objectMetadataIdToDelete,
|
|
relationFieldId,
|
|
}),
|
|
},
|
|
];
|
|
|
|
describe('Delete Object metadata with relation should succeed', () => {
|
|
let createdObjectMetadataPersonId: undefined | string;
|
|
let createdObjectMetadataOpportunityId: undefined | string;
|
|
let relationField: FieldMetadataDTO & {
|
|
relation: RelationDTO;
|
|
};
|
|
|
|
beforeEach(async () => {
|
|
const {
|
|
data: {
|
|
createOneObject: { id: objectMetadataPersonId },
|
|
},
|
|
} = await createOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
nameSingular: 'personForRelation',
|
|
namePlural: 'peopleForRelation',
|
|
labelSingular: 'Person For Relation',
|
|
labelPlural: 'People For Relation',
|
|
icon: 'IconPerson',
|
|
},
|
|
});
|
|
|
|
createdObjectMetadataPersonId = objectMetadataPersonId;
|
|
|
|
const {
|
|
data: {
|
|
createOneObject: { id: objectMetadataOpportunityId },
|
|
},
|
|
} = await createOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
nameSingular: 'opportunityForRelation',
|
|
namePlural: 'opportunitiesForRelation',
|
|
labelSingular: 'Opportunity For Relation',
|
|
labelPlural: 'Opportunities For Relation',
|
|
icon: 'IconOpportunity',
|
|
},
|
|
});
|
|
|
|
createdObjectMetadataOpportunityId = objectMetadataOpportunityId;
|
|
|
|
relationField =
|
|
await createRelationBetweenObjects<FieldMetadataType.RELATION>({
|
|
objectMetadataId: createdObjectMetadataOpportunityId,
|
|
targetObjectMetadataId: createdObjectMetadataPersonId,
|
|
type: FieldMetadataType.RELATION,
|
|
relationType: RelationType.MANY_TO_ONE,
|
|
});
|
|
});
|
|
|
|
afterEach(async () => {
|
|
if (isDefined(createdObjectMetadataPersonId)) {
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: createdObjectMetadataPersonId,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
await deleteOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: { idToDelete: createdObjectMetadataPersonId },
|
|
});
|
|
}
|
|
|
|
if (isDefined(createdObjectMetadataOpportunityId)) {
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: createdObjectMetadataOpportunityId,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
await deleteOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: { idToDelete: createdObjectMetadataOpportunityId },
|
|
});
|
|
}
|
|
});
|
|
|
|
it.each(successfulDeleteSourceUseCase)('$title', async ({ context }) => {
|
|
jestExpectToBeDefined(createdObjectMetadataPersonId);
|
|
const computedContext = context({
|
|
objectMetadataIdToDelete: createdObjectMetadataPersonId,
|
|
relationFieldId: relationField.id,
|
|
});
|
|
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: computedContext.objectMetadataIdToDelete,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
await deleteOneObjectMetadata({
|
|
input: { idToDelete: computedContext.objectMetadataIdToDelete },
|
|
});
|
|
|
|
createdObjectMetadataPersonId = undefined;
|
|
const opportunityFieldOnPersonAfterDeletion = await findFieldMetadata({
|
|
fieldMetadataId: computedContext.relationFieldId,
|
|
});
|
|
|
|
expect(opportunityFieldOnPersonAfterDeletion).toBeUndefined();
|
|
});
|
|
|
|
it.each(successfulDeleteTargetUseCase)('$title', async ({ context }) => {
|
|
jestExpectToBeDefined(createdObjectMetadataOpportunityId);
|
|
const computedContext = context({
|
|
objectMetadataIdToDelete: createdObjectMetadataOpportunityId,
|
|
relationFieldId: relationField.id,
|
|
});
|
|
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: computedContext.objectMetadataIdToDelete,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
await deleteOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: { idToDelete: computedContext.objectMetadataIdToDelete },
|
|
});
|
|
|
|
createdObjectMetadataOpportunityId = undefined;
|
|
const personFieldOnOpportunityAfterDeletion = await findFieldMetadata({
|
|
fieldMetadataId: computedContext.relationFieldId,
|
|
});
|
|
|
|
expect(personFieldOnOpportunityAfterDeletion).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
const findFieldMetadata = async ({
|
|
fieldMetadataId,
|
|
}: {
|
|
fieldMetadataId: string;
|
|
}) => {
|
|
const operation = findManyFieldsMetadataQueryFactory({
|
|
gqlFields: `
|
|
id
|
|
name
|
|
object {
|
|
id
|
|
nameSingular
|
|
}
|
|
relation {
|
|
type
|
|
targetFieldMetadata {
|
|
id
|
|
}
|
|
targetObjectMetadata {
|
|
id
|
|
}
|
|
}
|
|
settings
|
|
`,
|
|
input: {
|
|
filter: {
|
|
id: { eq: fieldMetadataId },
|
|
},
|
|
paging: { first: 1 },
|
|
},
|
|
});
|
|
|
|
const fields = await makeMetadataAPIRequest(operation);
|
|
const field = fields.body.data.fields.edges?.[0]?.node;
|
|
|
|
return field;
|
|
};
|