Skip to content

Commit

Permalink
Add tests for modules/object-metadata/hooks (#3485)
Browse files Browse the repository at this point in the history
* Add tests for `modules/object-metadata/hooks`

Co-authored-by: v1b3m <[email protected]>

* Merge main

Co-authored-by: v1b3m <[email protected]>

* Refactor according to self review

Co-authored-by: v1b3m <[email protected]>

---------

Co-authored-by: gitstart-twenty <[email protected]>
Co-authored-by: v1b3m <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2024
1 parent ba038a4 commit 6af2513
Show file tree
Hide file tree
Showing 30 changed files with 1,624 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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>
);
};
Original file line number Diff line number Diff line change
@@ -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: '',
};
Original file line number Diff line number Diff line change
@@ -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: '',
};
Original file line number Diff line number Diff line change
@@ -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: '',
};
Original file line number Diff line number Diff line change
@@ -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: [],
},
};
Original file line number Diff line number Diff line change
@@ -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: [] },
};
Loading

0 comments on commit 6af2513

Please sign in to comment.