Add tests for modules/object-metadata/hooks (#3485)
* Add tests for `modules/object-metadata/hooks` Co-authored-by: v1b3m <vibenjamin6@gmail.com> * Merge main Co-authored-by: v1b3m <vibenjamin6@gmail.com> * Refactor according to self review Co-authored-by: v1b3m <vibenjamin6@gmail.com> --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com>
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
import { ReactNode } from 'react';
|
||||
import {
|
||||
ApolloClient,
|
||||
NormalizedCacheObject,
|
||||
useApolloClient,
|
||||
} from '@apollo/client';
|
||||
|
||||
import { ApolloMetadataClientContext } from '@/object-metadata/context/ApolloClientMetadataContext';
|
||||
|
||||
export const TestApolloMetadataClientProvider = ({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) => {
|
||||
const client = useApolloClient() as ApolloClient<NormalizedCacheObject>;
|
||||
return (
|
||||
<ApolloMetadataClientContext.Provider value={client}>
|
||||
{client ? children : ''}
|
||||
</ApolloMetadataClientContext.Provider>
|
||||
);
|
||||
};
|
||||
@ -0,0 +1,50 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const query = gql`
|
||||
mutation CreateOneObjectMetadataItem($input: CreateOneObjectInput!) {
|
||||
createOneObject(input: $input) {
|
||||
id
|
||||
dataSourceId
|
||||
nameSingular
|
||||
namePlural
|
||||
labelSingular
|
||||
labelPlural
|
||||
description
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
createdAt
|
||||
updatedAt
|
||||
labelIdentifierFieldMetadataId
|
||||
imageIdentifierFieldMetadataId
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const variables = {
|
||||
input: {
|
||||
object: {
|
||||
labelPlural: 'View Filters',
|
||||
labelSingular: 'View Filter',
|
||||
nameSingular: 'viewFilter',
|
||||
namePlural: 'viewFilters',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const responseData = {
|
||||
id: '',
|
||||
dataSourceId: '',
|
||||
nameSingular: 'viewFilter',
|
||||
namePlural: 'viewFilters',
|
||||
labelSingular: 'View Filter',
|
||||
labelPlural: 'View Filters',
|
||||
description: '',
|
||||
icon: '',
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
createdAt: '',
|
||||
updatedAt: '',
|
||||
labelIdentifierFieldMetadataId: '',
|
||||
imageIdentifierFieldMetadataId: '',
|
||||
};
|
||||
@ -0,0 +1,45 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const query = gql`
|
||||
mutation CreateOneRelationMetadata($input: CreateOneRelationInput!) {
|
||||
createOneRelation(input: $input) {
|
||||
id
|
||||
relationType
|
||||
fromObjectMetadataId
|
||||
toObjectMetadataId
|
||||
fromFieldMetadataId
|
||||
toFieldMetadataId
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const variables = {
|
||||
input: {
|
||||
relation: {
|
||||
fromDescription: null,
|
||||
fromIcon: undefined,
|
||||
fromLabel: 'label',
|
||||
fromName: 'label',
|
||||
fromObjectMetadataId: 'objectMetadataId',
|
||||
relationType: 'ONE_TO_ONE',
|
||||
toDescription: null,
|
||||
toIcon: undefined,
|
||||
toLabel: 'Another label',
|
||||
toName: 'anotherLabel',
|
||||
toObjectMetadataId: 'objectMetadataId1',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const responseData = {
|
||||
id: '',
|
||||
relationType: 'ONE_TO_ONE',
|
||||
fromObjectMetadataId: 'objectMetadataId',
|
||||
toObjectMetadataId: 'objectMetadataId1',
|
||||
fromFieldMetadataId: '',
|
||||
toFieldMetadataId: '',
|
||||
createdAt: '',
|
||||
updatedAt: '',
|
||||
};
|
||||
@ -0,0 +1,41 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const query = gql`
|
||||
mutation DeleteOneObjectMetadataItem($idToDelete: ID!) {
|
||||
deleteOneObject(input: { id: $idToDelete }) {
|
||||
id
|
||||
dataSourceId
|
||||
nameSingular
|
||||
namePlural
|
||||
labelSingular
|
||||
labelPlural
|
||||
description
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
createdAt
|
||||
updatedAt
|
||||
labelIdentifierFieldMetadataId
|
||||
imageIdentifierFieldMetadataId
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const variables = { idToDelete: 'idToDelete' };
|
||||
|
||||
export const responseData = {
|
||||
id: '',
|
||||
dataSourceId: '',
|
||||
nameSingular: '',
|
||||
namePlural: '',
|
||||
labelSingular: '',
|
||||
labelPlural: '',
|
||||
description: '',
|
||||
icon: '',
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
createdAt: '',
|
||||
updatedAt: '',
|
||||
labelIdentifierFieldMetadataId: '',
|
||||
imageIdentifierFieldMetadataId: '',
|
||||
};
|
||||
@ -0,0 +1,107 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
const baseFields = `
|
||||
id
|
||||
type
|
||||
name
|
||||
label
|
||||
description
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
isNullable
|
||||
createdAt
|
||||
updatedAt
|
||||
`;
|
||||
|
||||
export const queries = {
|
||||
eraseMetadataField: gql`
|
||||
mutation DeleteOneFieldMetadataItem($idToDelete: ID!) {
|
||||
deleteOneField(input: { id: $idToDelete }) {
|
||||
${baseFields}
|
||||
}
|
||||
}
|
||||
`,
|
||||
activateMetadataField: gql`
|
||||
mutation UpdateOneFieldMetadataItem(
|
||||
$idToUpdate: ID!
|
||||
$updatePayload: UpdateFieldInput!
|
||||
) {
|
||||
updateOneField(input: { id: $idToUpdate, update: $updatePayload }) {
|
||||
${baseFields}
|
||||
}
|
||||
}
|
||||
`,
|
||||
createMetadataField: gql`
|
||||
mutation CreateOneFieldMetadataItem($input: CreateOneFieldMetadataInput!) {
|
||||
createOneField(input: $input) {
|
||||
${baseFields}
|
||||
defaultValue
|
||||
options
|
||||
}
|
||||
}
|
||||
`,
|
||||
};
|
||||
|
||||
const fieldId = '2c43466a-fe9e-4005-8d08-c5836067aa6c';
|
||||
export const objectMetadataId = '25611fce-6637-4089-b0ca-91afeec95784';
|
||||
|
||||
export const variables = {
|
||||
eraseMetadataField: { idToDelete: fieldId },
|
||||
activateMetadataField: {
|
||||
idToUpdate: fieldId,
|
||||
updatePayload: { isActive: true, label: undefined },
|
||||
},
|
||||
createMetadataField: {
|
||||
input: {
|
||||
field: {
|
||||
defaultValue: undefined,
|
||||
description: null,
|
||||
icon: undefined,
|
||||
label: 'fieldLabel',
|
||||
name: 'fieldLabel',
|
||||
options: undefined,
|
||||
objectMetadataId,
|
||||
type: 'TEXT',
|
||||
},
|
||||
},
|
||||
},
|
||||
disableMetadataField: {
|
||||
idToUpdate: fieldId,
|
||||
updatePayload: { isActive: false, label: undefined },
|
||||
},
|
||||
editMetadataField: {
|
||||
idToUpdate: '2c43466a-fe9e-4005-8d08-c5836067aa6c',
|
||||
updatePayload: {
|
||||
defaultValue: undefined,
|
||||
description: null,
|
||||
icon: undefined,
|
||||
label: 'New label',
|
||||
name: 'newLabel',
|
||||
options: undefined,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const defaultResponseData = {
|
||||
id: '2c43466a-fe9e-4005-8d08-c5836067aa6c',
|
||||
type: 'type',
|
||||
name: 'name',
|
||||
label: 'label',
|
||||
description: 'description',
|
||||
icon: 'icon',
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
isNullable: false,
|
||||
createdAt: '1977-09-28T13:56:55.157Z',
|
||||
updatedAt: '1996-10-10T08:27:57.117Z',
|
||||
};
|
||||
|
||||
export const responseData = {
|
||||
default: defaultResponseData,
|
||||
createMetadataField: {
|
||||
...defaultResponseData,
|
||||
defaultValue: '',
|
||||
options: [],
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,94 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const query = gql`
|
||||
query ObjectMetadataItems(
|
||||
$objectFilter: objectFilter
|
||||
$fieldFilter: fieldFilter
|
||||
) {
|
||||
objects(paging: { first: 1000 }, filter: $objectFilter) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
dataSourceId
|
||||
nameSingular
|
||||
namePlural
|
||||
labelSingular
|
||||
labelPlural
|
||||
description
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
isSystem
|
||||
createdAt
|
||||
updatedAt
|
||||
labelIdentifierFieldMetadataId
|
||||
imageIdentifierFieldMetadataId
|
||||
fields(paging: { first: 1000 }, filter: $fieldFilter) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
type
|
||||
name
|
||||
label
|
||||
description
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
isSystem
|
||||
isNullable
|
||||
createdAt
|
||||
updatedAt
|
||||
fromRelationMetadata {
|
||||
id
|
||||
relationType
|
||||
toObjectMetadata {
|
||||
id
|
||||
dataSourceId
|
||||
nameSingular
|
||||
namePlural
|
||||
isSystem
|
||||
}
|
||||
toFieldMetadataId
|
||||
}
|
||||
toRelationMetadata {
|
||||
id
|
||||
relationType
|
||||
fromObjectMetadata {
|
||||
id
|
||||
dataSourceId
|
||||
nameSingular
|
||||
namePlural
|
||||
isSystem
|
||||
}
|
||||
fromFieldMetadataId
|
||||
}
|
||||
defaultValue
|
||||
options
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
startCursor
|
||||
endCursor
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
startCursor
|
||||
endCursor
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const variables = { objectFilter: undefined, fieldFilter: undefined };
|
||||
|
||||
export const responseData = {
|
||||
objects: { edges: [] },
|
||||
};
|
||||
@ -0,0 +1,54 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const query = gql`
|
||||
mutation UpdateOneObjectMetadataItem(
|
||||
$idToUpdate: ID!
|
||||
$updatePayload: UpdateObjectInput!
|
||||
) {
|
||||
updateOneObject(input: { id: $idToUpdate, update: $updatePayload }) {
|
||||
id
|
||||
dataSourceId
|
||||
nameSingular
|
||||
namePlural
|
||||
labelSingular
|
||||
labelPlural
|
||||
description
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
createdAt
|
||||
updatedAt
|
||||
labelIdentifierFieldMetadataId
|
||||
imageIdentifierFieldMetadataId
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const variables = {
|
||||
idToUpdate: 'idToUpdate',
|
||||
updatePayload: {
|
||||
description: 'newDescription',
|
||||
icon: undefined,
|
||||
labelPlural: 'labelPlural',
|
||||
labelSingular: 'labelSingular',
|
||||
namePlural: 'labelPlural',
|
||||
nameSingular: 'labelSingular',
|
||||
},
|
||||
};
|
||||
|
||||
export const responseData = {
|
||||
id: 'idToUpdate',
|
||||
dataSourceId: 'dataSourceId',
|
||||
nameSingular: 'nameSingular',
|
||||
namePlural: 'namePlural',
|
||||
labelSingular: 'labelSingular',
|
||||
labelPlural: 'labelPlural',
|
||||
description: 'newDescription',
|
||||
icon: '',
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
createdAt: '',
|
||||
updatedAt: '',
|
||||
labelIdentifierFieldMetadataId: '',
|
||||
imageIdentifierFieldMetadataId: '',
|
||||
};
|
||||
Reference in New Issue
Block a user