-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests on object record mutation and query hooks (#5014)
### Description Add unit tests on object record mutation and query hooks ### Refs #4884 ### Demo ![Screenshot 2024-04-18 at 15 16 19](https://github.com/twentyhq/twenty/assets/140154534/c75f716a-725e-43eb-a703-3db29065fb18) Fixes #4884 --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
- Loading branch information
1 parent
d0759ad
commit d10efb1
Showing
12 changed files
with
727 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/twenty-front/src/modules/object-record/hooks/__mocks__/useFindDuplicateRecords.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,67 @@ | ||
import { gql } from '@apollo/client'; | ||
import { mockedPeopleData } from '~/testing/mock-data/people'; | ||
|
||
export const query = gql` | ||
query FindDuplicatePerson($id: UUID) { | ||
personDuplicates(id: $id) { | ||
edges { | ||
node { | ||
__typename | ||
xLink { | ||
label | ||
url | ||
} | ||
id | ||
createdAt | ||
city | ||
jobTitle | ||
name { | ||
firstName | ||
lastName | ||
} | ||
phone | ||
linkedinLink { | ||
label | ||
url | ||
} | ||
updatedAt | ||
avatarUrl | ||
companyId | ||
} | ||
cursor | ||
} | ||
pageInfo { | ||
hasNextPage | ||
startCursor | ||
endCursor | ||
} | ||
totalCount | ||
} | ||
} | ||
`; | ||
|
||
export const variables = { | ||
id: '6205681e-7c11-40b4-9e32-f523dbe54590', | ||
}; | ||
|
||
export const responseData = { | ||
personDuplicates: { | ||
edges: [ | ||
{ | ||
node: { __typename: 'Person', ...mockedPeopleData[0], updatedAt: '' }, | ||
cursor: 'cursor1', | ||
}, | ||
{ | ||
node: { __typename: 'Person', ...mockedPeopleData[1], updatedAt: '' }, | ||
cursor: 'cursor2', | ||
}, | ||
], | ||
pageInfo: { | ||
hasNextPage: false, | ||
startCursor: 'cursor1', | ||
endCursor: 'cursor2', | ||
}, | ||
totalCount: 2, | ||
}, | ||
}; |
63 changes: 63 additions & 0 deletions
63
...nty-front/src/modules/object-record/hooks/__tests__/useCreateManyRecordsMutation.test.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,63 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { print } from 'graphql'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
import { useCreateManyRecordsMutation } from '@/object-record/hooks/useCreateManyRecordsMutation'; | ||
|
||
const expectedQueryTemplate = ` | ||
mutation CreatePeople($data: [PersonCreateInput!]!) { | ||
createPeople(data: $data) { | ||
__typename | ||
xLink { | ||
label | ||
url | ||
} | ||
id | ||
createdAt | ||
city | ||
jobTitle | ||
name { | ||
firstName | ||
lastName | ||
} | ||
phone | ||
linkedinLink { | ||
label | ||
url | ||
} | ||
updatedAt | ||
avatarUrl | ||
companyId | ||
} | ||
} | ||
`.replace(/\s/g, ''); | ||
|
||
describe('useCreateManyRecordsMutation', () => { | ||
it('should return a valid createManyRecordsMutation', () => { | ||
const objectNameSingular = 'person'; | ||
const depth = 2; | ||
|
||
const { result } = renderHook( | ||
() => | ||
useCreateManyRecordsMutation({ | ||
objectNameSingular, | ||
depth, | ||
}), | ||
{ | ||
wrapper: RecoilRoot, | ||
}, | ||
); | ||
|
||
const { createManyRecordsMutation } = result.current; | ||
|
||
expect(createManyRecordsMutation).toBeDefined(); | ||
|
||
const printedReceivedQuery = print(createManyRecordsMutation).replace( | ||
/\s/g, | ||
'', | ||
); | ||
|
||
expect(printedReceivedQuery).toEqual(expectedQueryTemplate); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
...wenty-front/src/modules/object-record/hooks/__tests__/useCreateOneRecordMutation.test.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,63 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { print } from 'graphql'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
import { useCreateOneRecordMutation } from '@/object-record/hooks/useCreateOneRecordMutation'; | ||
|
||
const expectedQueryTemplate = ` | ||
mutation CreateOnePerson($input: PersonCreateInput!) { | ||
createPerson(data: $input) { | ||
__typename | ||
xLink { | ||
label | ||
url | ||
} | ||
id | ||
createdAt | ||
city | ||
jobTitle | ||
name { | ||
firstName | ||
lastName | ||
} | ||
phone | ||
linkedinLink { | ||
label | ||
url | ||
} | ||
updatedAt | ||
avatarUrl | ||
companyId | ||
} | ||
} | ||
`.replace(/\s/g, ''); | ||
|
||
describe('useCreateOneRecordMutation', () => { | ||
it('should return a valid createOneRecordMutation', () => { | ||
const objectNameSingular = 'person'; | ||
const depth = 2; | ||
|
||
const { result } = renderHook( | ||
() => | ||
useCreateOneRecordMutation({ | ||
objectNameSingular, | ||
depth, | ||
}), | ||
{ | ||
wrapper: RecoilRoot, | ||
}, | ||
); | ||
|
||
const { createOneRecordMutation } = result.current; | ||
|
||
expect(createOneRecordMutation).toBeDefined(); | ||
|
||
const printedReceivedQuery = print(createOneRecordMutation).replace( | ||
/\s/g, | ||
'', | ||
); | ||
|
||
expect(printedReceivedQuery).toEqual(expectedQueryTemplate); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
...nty-front/src/modules/object-record/hooks/__tests__/useDeleteManyRecordsMutation.test.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,40 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { print } from 'graphql'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
import { useDeleteManyRecordsMutation } from '@/object-record/hooks/useDeleteManyRecordsMutation'; | ||
|
||
const expectedQueryTemplate = ` | ||
mutation DeleteManyPeople($filter: PersonFilterInput!) { | ||
deletePeople(filter: $filter) { | ||
id | ||
} | ||
} | ||
`.replace(/\s/g, ''); | ||
|
||
describe('useDeleteManyRecordsMutation', () => { | ||
it('should return a valid deleteManyRecordsMutation', () => { | ||
const objectNameSingular = 'person'; | ||
|
||
const { result } = renderHook( | ||
() => | ||
useDeleteManyRecordsMutation({ | ||
objectNameSingular, | ||
}), | ||
{ | ||
wrapper: RecoilRoot, | ||
}, | ||
); | ||
|
||
const { deleteManyRecordsMutation } = result.current; | ||
|
||
expect(deleteManyRecordsMutation).toBeDefined(); | ||
|
||
const printedReceivedQuery = print(deleteManyRecordsMutation).replace( | ||
/\s/g, | ||
'', | ||
); | ||
|
||
expect(printedReceivedQuery).toEqual(expectedQueryTemplate); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
...wenty-front/src/modules/object-record/hooks/__tests__/useDeleteOneRecordMutation.test.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,40 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { print } from 'graphql'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
import { useDeleteOneRecordMutation } from '@/object-record/hooks/useDeleteOneRecordMutation'; | ||
|
||
const expectedQueryTemplate = ` | ||
mutation DeleteOnePerson($idToDelete: UUID!) { | ||
deletePerson(id: $idToDelete) { | ||
id | ||
} | ||
} | ||
`.replace(/\s/g, ''); | ||
|
||
describe('useDeleteOneRecordMutation', () => { | ||
it('should return a valid deleteOneRecordMutation', () => { | ||
const objectNameSingular = 'person'; | ||
|
||
const { result } = renderHook( | ||
() => | ||
useDeleteOneRecordMutation({ | ||
objectNameSingular, | ||
}), | ||
{ | ||
wrapper: RecoilRoot, | ||
}, | ||
); | ||
|
||
const { deleteOneRecordMutation } = result.current; | ||
|
||
expect(deleteOneRecordMutation).toBeDefined(); | ||
|
||
const printedReceivedQuery = print(deleteOneRecordMutation).replace( | ||
/\s/g, | ||
'', | ||
); | ||
|
||
expect(printedReceivedQuery).toEqual(expectedQueryTemplate); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
...c/modules/object-record/hooks/__tests__/useExecuteQuickActionOnOneRecordMutation.test.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,60 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { print } from 'graphql'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
import { useExecuteQuickActionOnOneRecordMutation } from '@/object-record/hooks/useExecuteQuickActionOnOneRecordMutation'; | ||
|
||
const expectedQueryTemplate = ` | ||
mutation ExecuteQuickActionOnOnePerson($idToExecuteQuickActionOn: UUID!) { | ||
executeQuickActionOnPerson(id: $idToExecuteQuickActionOn) { | ||
__typename | ||
xLink { | ||
label | ||
url | ||
} | ||
id | ||
createdAt | ||
city | ||
jobTitle | ||
name { | ||
firstName | ||
lastName | ||
} | ||
phone | ||
linkedinLink { | ||
label | ||
url | ||
} | ||
updatedAt | ||
avatarUrl | ||
companyId | ||
} | ||
} | ||
`.replace(/\s/g, ''); | ||
|
||
describe('useExecuteQuickActionOnOneRecordMutation', () => { | ||
it('should return a valid executeQuickActionOnOneRecordMutation', () => { | ||
const objectNameSingular = 'person'; | ||
|
||
const { result } = renderHook( | ||
() => | ||
useExecuteQuickActionOnOneRecordMutation({ | ||
objectNameSingular, | ||
}), | ||
{ | ||
wrapper: RecoilRoot, | ||
}, | ||
); | ||
|
||
const { executeQuickActionOnOneRecordMutation } = result.current; | ||
|
||
expect(executeQuickActionOnOneRecordMutation).toBeDefined(); | ||
|
||
const printedReceivedQuery = print( | ||
executeQuickActionOnOneRecordMutation, | ||
).replace(/\s/g, ''); | ||
|
||
expect(printedReceivedQuery).toEqual(expectedQueryTemplate); | ||
}); | ||
}); |
Oops, something went wrong.