Skip to content

Commit

Permalink
Updating handoff link to use new userId from userPreferences
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Jun 7, 2024
1 parent 46587b9 commit 417bab1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/components/HandoffLink/HandoffLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ 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', () => {
let open: jest.Mock;
let originalOpen: Window['open'];
const useRouter = jest.spyOn(nextRouter, 'useRouter');
const rewriteDomain = process.env.REWRITE_DOMAIN;
const userId = 'userID123';

beforeEach(() => {
open = jest.fn();
Expand All @@ -32,9 +34,11 @@ describe('HandoffLink', () => {
it('default', async () => {
const { getByRole } = render(
<GqlMockedProvider>
<HandoffLink path="/contacts">
<a>Link</a>
</HandoffLink>
<UserPreferenceContext.Provider value={{ userId, locale: 'en-US' }}>
<HandoffLink path="/contacts">
<a>Link</a>
</HandoffLink>
</UserPreferenceContext.Provider>
</GqlMockedProvider>,
);
const linkElement = getByRole('link', { hidden: true, name: 'Link' });
Expand All @@ -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',
);
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/HandoffLink/HandoffLink.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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`,
Expand All @@ -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);

Expand Down

0 comments on commit 417bab1

Please sign in to comment.