-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
modules/object-metadata/hooks
(#3485)
* 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
1 parent
ba038a4
commit 6af2513
Showing
30 changed files
with
1,624 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...twenty-front/src/modules/object-metadata/hooks/__mocks__/ApolloMetadataClientProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
50 changes: 50 additions & 0 deletions
50
...front/src/modules/object-metadata/hooks/__mocks__/useCreateOneObjectRecordMetadataItem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '', | ||
}; |
45 changes: 45 additions & 0 deletions
45
...nty-front/src/modules/object-metadata/hooks/__mocks__/useCreateOneRelationMetadataItem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '', | ||
}; |
41 changes: 41 additions & 0 deletions
41
...wenty-front/src/modules/object-metadata/hooks/__mocks__/useDeleteOneObjectMetadataItem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '', | ||
}; |
107 changes: 107 additions & 0 deletions
107
packages/twenty-front/src/modules/object-metadata/hooks/__mocks__/useFieldMetadataItem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [], | ||
}, | ||
}; |
94 changes: 94 additions & 0 deletions
94
...wenty-front/src/modules/object-metadata/hooks/__mocks__/useFindManyObjectMetadataItems.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] }, | ||
}; |
Oops, something went wrong.