4ecc9c622d
# Introduction
Initial motivation here was to migrate the object related records logic
from v1 to v2, please note that now in v2 views aren't records anymore
but core engine entities
## What's done
- Added specific label identifier targeting view field logic
- Handled side effects on viewField creation with lowest position on
object label identifier mutation
- Added viewField relations in field metadate entity + handled
optimistic in builder v2
- Added view relations in object metadata entity + handled optimistic in
builder v2
- Added integration tests covering the side effects and new validation
exceptions
- Sandardized cache computation
- Coverage on object metadata creation side effect on views and view
fields
## Coverage
```ts
PASS test/integration/graphql/suites/view/view-field/object-identifier-update-side-effect-on-view-field.integration-spec.ts
View Field Resolver - Successful object metadata identifier update side effect on view field
✓ should create a view field on label identifier object metadata update if it does not exist on view (7 ms)
✓ Should not allow deleting a label identifier view field (17 ms)
✓ Should not allow destroying a label identifier view field (6 ms)
✓ Should not allow updating a label identifier view field visibility to false (8 ms)
✓ Should not allow creating a view field with a position lower than the label idenfitier view field (180 ms)
✓ Should not allow updated labelIdentifier view field with a position higher than existing other view field (346 ms)
✓ Should allow updated labelIdentifier view field with a position higher than existing other view field (434 ms)
Test Suites: 1 passed, 1 total
Tests: 7 passed, 7 total
Snapshots: 5 passed, 5 total
Time: 4.571 s, estimated 5 s
```
close https://github.com/twentyhq/core-team-issues/issues/1664
190 lines
5.7 KiB
TypeScript
190 lines
5.7 KiB
TypeScript
import { findManyFieldsMetadataQueryFactory } from 'test/integration/metadata/suites/field-metadata/utils/find-many-fields-metadata-query-factory.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 { findManyObjectMetadataQueryFactory } from 'test/integration/metadata/suites/object-metadata/utils/find-many-object-metadata-query-factory.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 { FieldMetadataType } from 'twenty-shared/types';
|
|
|
|
describe('Custom object renaming', () => {
|
|
let listingObjectId = '';
|
|
|
|
const STANDARD_OBJECT_RELATIONS = [
|
|
'noteTarget',
|
|
'attachment',
|
|
'favorite',
|
|
'taskTarget',
|
|
'timelineActivity',
|
|
];
|
|
|
|
const standardObjectRelationsMap = STANDARD_OBJECT_RELATIONS.reduce(
|
|
(acc, relation) => ({
|
|
...acc,
|
|
[relation]: {
|
|
objectMetadataId: '',
|
|
foreignKeyFieldMetadataId: '',
|
|
relationFieldMetadataId: '',
|
|
},
|
|
}),
|
|
{},
|
|
);
|
|
|
|
const standardObjectsGraphqlOperation = findManyObjectMetadataQueryFactory({
|
|
gqlFields: `
|
|
id
|
|
nameSingular
|
|
`,
|
|
input: {
|
|
filter: {
|
|
isCustom: { isNot: true },
|
|
},
|
|
paging: { first: 1000 },
|
|
},
|
|
});
|
|
|
|
const fieldsGraphqlOperation = findManyFieldsMetadataQueryFactory({
|
|
gqlFields: `
|
|
id
|
|
name
|
|
label
|
|
type
|
|
object {
|
|
id
|
|
}
|
|
`,
|
|
input: {
|
|
filter: {},
|
|
paging: { first: 1000 },
|
|
},
|
|
});
|
|
|
|
// @ts-expect-error legacy noImplicitAny
|
|
const fillStandardObjectRelationsMapObjectMetadataId = (standardObjects) => {
|
|
STANDARD_OBJECT_RELATIONS.forEach((relation) => {
|
|
// @ts-expect-error legacy noImplicitAny
|
|
standardObjectRelationsMap[relation].objectMetadataId =
|
|
standardObjects.body.data.objects.edges.find(
|
|
// @ts-expect-error legacy noImplicitAny
|
|
(object) => object.node.nameSingular === relation,
|
|
).node.id;
|
|
});
|
|
};
|
|
|
|
it('1. should create one custom object with standard relations', async () => {
|
|
// Arrange
|
|
const standardObjects = await makeMetadataAPIRequest(
|
|
standardObjectsGraphqlOperation,
|
|
);
|
|
|
|
fillStandardObjectRelationsMapObjectMetadataId(standardObjects);
|
|
|
|
const CUSTOM_OBJECT = {
|
|
namePlural: 'customObjectNamePlural',
|
|
nameSingular: 'customObjectNameSingular',
|
|
labelPlural: 'customObjectLabelPlural',
|
|
labelSingular: 'customObjectLabelSingular',
|
|
description: 'Custom object description',
|
|
icon: 'IconListNumbers',
|
|
isLabelSyncedWithName: false,
|
|
};
|
|
|
|
// Act
|
|
const { data } = await createOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: CUSTOM_OBJECT,
|
|
gqlFields: `
|
|
id
|
|
nameSingular
|
|
`,
|
|
});
|
|
|
|
// Assert
|
|
expect(data.createOneObject.nameSingular).toBe(CUSTOM_OBJECT.nameSingular);
|
|
|
|
listingObjectId = data.createOneObject.id;
|
|
|
|
const fields = await makeMetadataAPIRequest(fieldsGraphqlOperation);
|
|
|
|
const relationFieldsMetadataForListing = fields.body.data.fields.edges
|
|
.filter(
|
|
// @ts-expect-error legacy noImplicitAny
|
|
(field) =>
|
|
field.node.name === `${CUSTOM_OBJECT.nameSingular}` &&
|
|
field.node.type === FieldMetadataType.RELATION,
|
|
)
|
|
// @ts-expect-error legacy noImplicitAny
|
|
.map((field) => field.node);
|
|
|
|
STANDARD_OBJECT_RELATIONS.forEach((relation) => {
|
|
// relation field
|
|
const relationFieldMetadataId = relationFieldsMetadataForListing.find(
|
|
// @ts-expect-error legacy noImplicitAny
|
|
(field) =>
|
|
field.object.id ===
|
|
// @ts-expect-error legacy noImplicitAny
|
|
standardObjectRelationsMap[relation].objectMetadataId,
|
|
).id;
|
|
|
|
expect(relationFieldMetadataId).not.toBeUndefined();
|
|
|
|
// @ts-expect-error legacy noImplicitAny
|
|
standardObjectRelationsMap[relation].relationFieldMetadataId =
|
|
relationFieldMetadataId;
|
|
});
|
|
});
|
|
|
|
it('2. should rename custom object', async () => {
|
|
// Arrange
|
|
const HOUSE_NAME_SINGULAR = 'house';
|
|
const HOUSE_NAME_PLURAL = 'houses';
|
|
const HOUSE_LABEL_SINGULAR = 'House';
|
|
const HOUSE_LABEL_PLURAL = 'Houses';
|
|
|
|
// Act
|
|
const { data } = await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
gqlFields: `
|
|
nameSingular
|
|
labelSingular
|
|
namePlural
|
|
labelPlural
|
|
`,
|
|
input: {
|
|
idToUpdate: listingObjectId,
|
|
updatePayload: {
|
|
nameSingular: HOUSE_NAME_SINGULAR,
|
|
namePlural: HOUSE_NAME_PLURAL,
|
|
labelSingular: HOUSE_LABEL_SINGULAR,
|
|
labelPlural: HOUSE_LABEL_PLURAL,
|
|
},
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
expect(data.updateOneObject.nameSingular).toBe(HOUSE_NAME_SINGULAR);
|
|
expect(data.updateOneObject.namePlural).toBe(HOUSE_NAME_PLURAL);
|
|
expect(data.updateOneObject.labelSingular).toBe(HOUSE_LABEL_SINGULAR);
|
|
expect(data.updateOneObject.labelPlural).toBe(HOUSE_LABEL_PLURAL);
|
|
});
|
|
|
|
it('3. should delete custom object', async () => {
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: listingObjectId,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
const { data } = await deleteOneObjectMetadata({
|
|
input: {
|
|
idToDelete: listingObjectId,
|
|
},
|
|
});
|
|
|
|
expect(data.deleteOneObject.id).toBe(listingObjectId);
|
|
});
|
|
});
|