diff --git a/src/components/HandoffLink/HandoffLink.test.tsx b/src/components/HandoffLink/HandoffLink.test.tsx index 0ab0ba635..7871a1820 100644 --- a/src/components/HandoffLink/HandoffLink.test.tsx +++ b/src/components/HandoffLink/HandoffLink.test.tsx @@ -3,6 +3,7 @@ import React from 'react'; import { render } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; +import { UserPreferenceContext } from '../User/Preferences/UserPreferenceProvider'; import HandoffLink from '.'; describe('HandoffLink', () => { @@ -10,6 +11,7 @@ describe('HandoffLink', () => { let originalOpen: Window['open']; const useRouter = jest.spyOn(nextRouter, 'useRouter'); const rewriteDomain = process.env.REWRITE_DOMAIN; + const userId = 'userID123'; beforeEach(() => { open = jest.fn(); @@ -32,9 +34,11 @@ describe('HandoffLink', () => { it('default', async () => { const { getByRole } = render( - - Link - + + + Link + + , ); const linkElement = getByRole('link', { hidden: true, name: 'Link' }); @@ -43,9 +47,8 @@ describe('HandoffLink', () => { `https://${rewriteDomain}/contacts`, ); userEvent.click(linkElement); - // TODO investigate why the user is undefined when click fires expect(open).toHaveBeenCalledWith( - `${process.env.SITE_URL}/api/handoff?accountListId=accountListId&userId=user-1&path=%2Fcontacts`, + `${process.env.SITE_URL}/api/handoff?accountListId=accountListId&userId=${userId}&path=%2Fcontacts`, '_blank', ); }); diff --git a/src/components/HandoffLink/HandoffLink.tsx b/src/components/HandoffLink/HandoffLink.tsx index 899b93166..458f8a89f 100644 --- a/src/components/HandoffLink/HandoffLink.tsx +++ b/src/components/HandoffLink/HandoffLink.tsx @@ -1,6 +1,6 @@ import { Children, ReactElement, ReactNode, cloneElement } from 'react'; -import { useRequiredSession } from 'src/hooks/useRequiredSession'; import { useAccountListId } from '../../hooks/useAccountListId'; +import { useUserPreferenceContext } from '../User/Preferences/UserPreferenceProvider'; interface Props { path: string; @@ -9,8 +9,8 @@ interface Props { } const HandoffLink = ({ path, auth, children }: Props): ReactElement => { - const session = useRequiredSession(); const accountListId = useAccountListId(); + const { userId } = useUserPreferenceContext(); const url = new URL( `${process.env.SITE_URL || window.location.origin}/api/handoff`, @@ -20,7 +20,7 @@ const HandoffLink = ({ path, auth, children }: Props): ReactElement => { url.searchParams.append('auth', 'true'); } else { url.searchParams.append('accountListId', accountListId ?? ''); - url.searchParams.append('userId', session.userID); + url.searchParams.append('userId', userId ?? ''); } url.searchParams.append('path', path);