diff --git a/packages/twenty-front/src/modules/auth/hooks/__mocks__/useAuth.ts b/packages/twenty-front/src/modules/auth/hooks/__mocks__/useAuth.ts index aaa0bbc6b40e..32016c3ecbdd 100644 --- a/packages/twenty-front/src/modules/auth/hooks/__mocks__/useAuth.ts +++ b/packages/twenty-front/src/modules/auth/hooks/__mocks__/useAuth.ts @@ -1,5 +1,6 @@ import { ChallengeDocument, + GetCurrentUserDocument, SignUpDocument, VerifyDocument, } from '~/generated/graphql'; @@ -8,6 +9,7 @@ export const queries = { challenge: ChallengeDocument, verify: VerifyDocument, signup: SignUpDocument, + getCurrentUser: GetCurrentUserDocument, }; export const email = 'test@test.com'; @@ -22,6 +24,7 @@ export const variables = { }, verify: { loginToken: token }, signup: {}, + getCurrentUser: {}, }; export const results = { @@ -32,7 +35,14 @@ export const results = { }, }, verify: { - user: { + tokens: { + accessToken: { token, expiresAt: 'expiresAt' }, + refreshToken: { token, expiresAt: 'expiresAt' }, + }, + }, + signUp: { loginToken: { token, expiresAt: 'expiresAt' } }, + getCurrentUser: { + currentUser: { id: 'id', firstName: 'firstName', lastName: 'lastName', @@ -65,13 +75,7 @@ export const results = { }, }, }, - tokens: { - accessToken: { token, expiresAt: 'expiresAt' }, - refreshToken: { token, expiresAt: 'expiresAt' }, - }, - signup: {}, }, - signUp: { loginToken: { token, expiresAt: 'expiresAt' } }, }; export const mocks = [ @@ -108,4 +112,13 @@ export const mocks = [ }, })), }, + { + request: { + query: queries.getCurrentUser, + variables: variables.getCurrentUser, + }, + result: jest.fn(() => ({ + data: results.getCurrentUser, + })), + }, ]; diff --git a/packages/twenty-front/src/modules/auth/hooks/__tests__/useAuth.test.tsx b/packages/twenty-front/src/modules/auth/hooks/__tests__/useAuth.test.tsx index 7fea507688ed..6430246e359f 100644 --- a/packages/twenty-front/src/modules/auth/hooks/__tests__/useAuth.test.tsx +++ b/packages/twenty-front/src/modules/auth/hooks/__tests__/useAuth.test.tsx @@ -1,8 +1,7 @@ import { useApolloClient } from '@apollo/client'; import { MockedProvider } from '@apollo/client/testing'; import { expect } from '@storybook/test'; -import { act, renderHook } from '@testing-library/react'; -import { ReactNode } from 'react'; +import { ReactNode, act } from 'react'; import { RecoilRoot, useRecoilValue } from 'recoil'; import { iconsState } from 'twenty-ui'; @@ -15,6 +14,7 @@ import { workspaceAuthProvidersState } from '@/workspace/states/workspaceAuthPro import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWorkspaceEnabledState'; import { email, mocks, password, results, token } from '../__mocks__/useAuth'; +import { renderHook } from '@testing-library/react'; const Wrapper = ({ children }: { children: ReactNode }) => ( @@ -59,6 +59,7 @@ describe('useAuth', () => { }); expect(mocks[1].result).toHaveBeenCalled(); + expect(mocks[3].result).toHaveBeenCalled(); }); it('should handle credential sign-in', async () => {