Add integration tests for /metadata + fix relation deletion (#8706)
In this PR 1. Add integration tests for /metadata (master issue: https://github.com/twentyhq/twenty/issues/8719) 2. Fix relation deletion: index on "from" object was not deleted, impeding creation of a new relation between the same two objects A and B after relation between A and B was deleted
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
import { CreateObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/create-object.input';
|
||||
|
||||
type CreateOneObjectFactoryParams = {
|
||||
gqlFields: string;
|
||||
input?: { object: Omit<CreateObjectInput, 'workspaceId' | 'dataSourceId'> };
|
||||
};
|
||||
|
||||
export const createOneObjectMetadataFactory = ({
|
||||
gqlFields,
|
||||
input,
|
||||
}: CreateOneObjectFactoryParams) => ({
|
||||
query: gql`
|
||||
mutation CreateOneObjectMetadataItem($input: CreateOneObjectInput!) {
|
||||
createOneObject(input: $input) {
|
||||
${gqlFields}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
input,
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,26 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
import { CreateRelationInput } from 'src/engine/metadata-modules/relation-metadata/dtos/create-relation.input';
|
||||
|
||||
type CreateOneRelationFactoryParams = {
|
||||
gqlFields: string;
|
||||
input?: {
|
||||
relation: Omit<CreateRelationInput, 'workspaceId'>;
|
||||
};
|
||||
};
|
||||
|
||||
export const createOneRelationMetadataFactory = ({
|
||||
gqlFields,
|
||||
input,
|
||||
}: CreateOneRelationFactoryParams) => ({
|
||||
query: gql`
|
||||
mutation CreateOneRelationMetadata($input: CreateOneRelationInput!) {
|
||||
createOneRelation(input: $input) {
|
||||
${gqlFields}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
input,
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,20 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
type DeleteOneObjectFactoryParams = {
|
||||
idToDelete: string;
|
||||
};
|
||||
|
||||
export const deleteOneObjectMetadataItemFactory = ({
|
||||
idToDelete,
|
||||
}: DeleteOneObjectFactoryParams) => ({
|
||||
query: gql`
|
||||
mutation DeleteOneObjectMetadataItem($idToDelete: UUID!) {
|
||||
deleteOneObject(input: { id: $idToDelete }) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
idToDelete,
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,22 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
type DeleteOneRelationFactoryParams = {
|
||||
idToDelete: string;
|
||||
};
|
||||
|
||||
export const deleteOneRelationMetadataItemFactory = ({
|
||||
idToDelete,
|
||||
}: DeleteOneRelationFactoryParams) => ({
|
||||
query: gql`
|
||||
mutation DeleteOneRelation($input: DeleteOneRelationInput!) {
|
||||
deleteOneRelation(input: $input) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
input: {
|
||||
id: idToDelete,
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,30 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
type FieldsFactoryParams = {
|
||||
gqlFields: string;
|
||||
input: {
|
||||
filter: object;
|
||||
paging: object;
|
||||
};
|
||||
};
|
||||
|
||||
export const fieldsMetadataFactory = ({
|
||||
gqlFields,
|
||||
input,
|
||||
}: FieldsFactoryParams) => ({
|
||||
query: gql`
|
||||
query FieldsMetadata($filter: fieldFilter!, $paging: CursorPaging!) {
|
||||
fields(filter: $filter, paging: $paging) {
|
||||
edges {
|
||||
node {
|
||||
${gqlFields}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
filter: input.filter,
|
||||
paging: input.paging,
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
import { ASTNode, print } from 'graphql';
|
||||
import request from 'supertest';
|
||||
|
||||
type GraphqlOperation = {
|
||||
query: ASTNode;
|
||||
variables?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export const makeMetadataAPIRequest = (graphqlOperation: GraphqlOperation) => {
|
||||
const client = request(`http://localhost:${APP_PORT}`);
|
||||
|
||||
return client
|
||||
.post('/metadata')
|
||||
.set('Authorization', `Bearer ${ACCESS_TOKEN}`)
|
||||
.send({
|
||||
query: print(graphqlOperation.query),
|
||||
variables: graphqlOperation.variables || {},
|
||||
});
|
||||
};
|
||||
@ -0,0 +1,30 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
type ObjectsFactoryParams = {
|
||||
gqlFields: string;
|
||||
input: {
|
||||
filter: object;
|
||||
paging: object;
|
||||
};
|
||||
};
|
||||
|
||||
export const objectsMetadataFactory = ({
|
||||
gqlFields,
|
||||
input,
|
||||
}: ObjectsFactoryParams) => ({
|
||||
query: gql`
|
||||
query ObjectsMetadata($filter: objectFilter!, $paging: CursorPaging!) {
|
||||
objects(filter: $filter, paging: $paging) {
|
||||
edges {
|
||||
node {
|
||||
${gqlFields}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
filter: input.filter,
|
||||
paging: input.paging,
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,28 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
import { UpdateObjectPayload } from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input';
|
||||
|
||||
type UpdateOneObjectFactoryParams = {
|
||||
gqlFields: string;
|
||||
input: {
|
||||
idToUpdate: string;
|
||||
updatePayload: UpdateObjectPayload;
|
||||
};
|
||||
};
|
||||
|
||||
export const updateOneObjectMetadataItemFactory = ({
|
||||
gqlFields,
|
||||
input,
|
||||
}: UpdateOneObjectFactoryParams) => ({
|
||||
query: gql`
|
||||
mutation UpdateOneObjectMetadataItem($idToUpdate: UUID!, $updatePayload: UpdateObjectPayload!) {
|
||||
updateOneObject(input: {id: $idToUpdate, update: $updatePayload}) {
|
||||
${gqlFields}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
idToUpdate: input.idToUpdate,
|
||||
updatePayload: input.updatePayload,
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user