Refactor backend folder structure (#4505)
* Refactor backend folder structure Co-authored-by: Charles Bochet <charles@twenty.com> * fix tests * fix * move yoga hooks --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,104 @@
|
||||
import { FieldMetadataInterface } from 'src/engine-metadata/field-metadata/interfaces/field-metadata.interface';
|
||||
import { RelationMetadataInterface } from 'src/engine-metadata/field-metadata/interfaces/relation-metadata.interface';
|
||||
|
||||
import { FieldMetadataType } from 'src/engine-metadata/field-metadata/field-metadata.entity';
|
||||
import { RelationMetadataType } from 'src/engine-metadata/relation-metadata/relation-metadata.entity';
|
||||
import {
|
||||
deduceRelationDirection,
|
||||
RelationDirection,
|
||||
} from 'src/engine/utils/deduce-relation-direction.util';
|
||||
|
||||
describe('deduceRelationDirection', () => {
|
||||
it('should return FROM when the current object Metadata ID matches fromObjectMetadataId and id matches fromFieldMetadataId', () => {
|
||||
const fieldMetadata: FieldMetadataInterface = {
|
||||
id: 'field_id',
|
||||
objectMetadataId: 'from_object_id',
|
||||
type: FieldMetadataType.RELATION,
|
||||
name: 'field_name',
|
||||
label: 'Field Name',
|
||||
description: 'Field Description',
|
||||
targetColumnMap: {
|
||||
default: 'default_column',
|
||||
},
|
||||
};
|
||||
|
||||
const relationMetadata = {
|
||||
id: 'relation_id',
|
||||
fromObjectMetadataId: fieldMetadata.objectMetadataId,
|
||||
toObjectMetadataId: 'to_object_id',
|
||||
fromFieldMetadataId: fieldMetadata.id,
|
||||
toFieldMetadataId: 'to_field_id',
|
||||
relationType: RelationMetadataType.ONE_TO_ONE,
|
||||
};
|
||||
|
||||
const result = deduceRelationDirection(
|
||||
fieldMetadata,
|
||||
relationMetadata as RelationMetadataInterface,
|
||||
);
|
||||
|
||||
expect(result).toBe(RelationDirection.FROM);
|
||||
});
|
||||
|
||||
it('should return TO when the current object Metadata ID matches toObjectMetadataId and id matches toFieldMetadataId', () => {
|
||||
// Arrange
|
||||
const fieldMetadata: FieldMetadataInterface = {
|
||||
id: 'field_id',
|
||||
objectMetadataId: 'to_object_id',
|
||||
type: FieldMetadataType.RELATION,
|
||||
name: 'field_name',
|
||||
label: 'Field Name',
|
||||
description: 'Field Description',
|
||||
targetColumnMap: {
|
||||
default: 'default_column',
|
||||
},
|
||||
};
|
||||
|
||||
const relationMetadata = {
|
||||
id: 'relation_id',
|
||||
fromObjectMetadataId: 'from_object_id',
|
||||
toObjectMetadataId: fieldMetadata.objectMetadataId,
|
||||
fromFieldMetadataId: 'from_field_id',
|
||||
toFieldMetadataId: fieldMetadata.id,
|
||||
relationType: RelationMetadataType.ONE_TO_ONE,
|
||||
};
|
||||
|
||||
const result = deduceRelationDirection(
|
||||
fieldMetadata,
|
||||
relationMetadata as RelationMetadataInterface,
|
||||
);
|
||||
|
||||
expect(result).toBe(RelationDirection.TO);
|
||||
});
|
||||
|
||||
it('should throw an error when the current object Metadata ID does not match any object metadata ID', () => {
|
||||
const fieldMetadata: FieldMetadataInterface = {
|
||||
id: 'field_id',
|
||||
objectMetadataId: 'unrelated_object_id',
|
||||
type: FieldMetadataType.RELATION,
|
||||
name: 'field_name',
|
||||
label: 'Field Name',
|
||||
description: 'Field Description',
|
||||
targetColumnMap: {
|
||||
default: 'default_column',
|
||||
},
|
||||
};
|
||||
|
||||
const relationMetadata = {
|
||||
id: 'relation_id',
|
||||
fromObjectMetadataId: 'from_object_id',
|
||||
toObjectMetadataId: 'to_object_id',
|
||||
fromFieldMetadataId: 'from_field_id',
|
||||
toFieldMetadataId: 'to_field_id',
|
||||
relationType: RelationMetadataType.ONE_TO_ONE,
|
||||
};
|
||||
|
||||
expect(() =>
|
||||
deduceRelationDirection(
|
||||
fieldMetadata,
|
||||
relationMetadata as RelationMetadataInterface,
|
||||
),
|
||||
).toThrow(
|
||||
`Relation metadata ${relationMetadata.id} is not related to object ${fieldMetadata.objectMetadataId}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,35 @@
|
||||
import { WorkspaceResolverBuilderMethodNames } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
|
||||
|
||||
import { getResolverName } from 'src/engine/utils/get-resolver-name.util';
|
||||
|
||||
describe('getResolverName', () => {
|
||||
const metadata = {
|
||||
nameSingular: 'entity',
|
||||
namePlural: 'entities',
|
||||
};
|
||||
|
||||
it.each([
|
||||
['findMany', 'entities'],
|
||||
['findOne', 'entity'],
|
||||
['createMany', 'createEntities'],
|
||||
['createOne', 'createEntity'],
|
||||
['updateOne', 'updateEntity'],
|
||||
['deleteOne', 'deleteEntity'],
|
||||
['executeQuickActionOnOne', 'executeQuickActionOnEntity'],
|
||||
])('should return correct name for %s resolver', (type, expectedResult) => {
|
||||
expect(
|
||||
getResolverName(metadata, type as WorkspaceResolverBuilderMethodNames),
|
||||
).toBe(expectedResult);
|
||||
});
|
||||
|
||||
it('should throw an error for an unknown resolver type', () => {
|
||||
const unknownType = 'unknownType';
|
||||
|
||||
expect(() =>
|
||||
getResolverName(
|
||||
metadata,
|
||||
unknownType as WorkspaceResolverBuilderMethodNames,
|
||||
),
|
||||
).toThrow(`Unknown resolver type: ${unknownType}`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user