Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToU - pass along skip_mhv_account_creation parameter on accept #33008

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/applications/terms-of-use/containers/TermsOfUse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,20 @@ export default function TermsOfUse() {
);

const handleTouClick = async type => {
const termsCode = termsCodeExists
? `?terms_code=${redirectLocation.searchParams.get('terms_code')}`
: '';
const params = {
...(redirectLocation.searchParams.get('terms_code') && {
// eslint-disable-next-line camelcase
asg5704 marked this conversation as resolved.
Show resolved Hide resolved
terms_code: redirectLocation.searchParams.get('terms_code'),
}),
...(redirectLocation.searchParams.get('skip_mhv_account_creation') && {
// eslint-disable-next-line camelcase
asg5704 marked this conversation as resolved.
Show resolved Hide resolved
skip_mhv_account_creation: redirectLocation.searchParams.get(
'skip_mhv_account_creation',
),
}),
};

const queryString = `?${new URLSearchParams(params).toString()}`;

setButtonPushed(buttonPushed + 1);

Expand All @@ -93,7 +104,7 @@ export default function TermsOfUse() {

setIsDisabled(true);
const response = await apiRequest(
`/terms_of_use_agreements/v1/${type}${termsCode}`,
`/terms_of_use_agreements/v1/${type}${queryString}`,
{
method: 'POST',
credentials: 'include',
Expand Down
35 changes: 35 additions & 0 deletions src/applications/terms-of-use/tests/TermsOfUse.unit.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,41 @@ describe('TermsOfUse', () => {
});
});

it('should pass along `skip_mhv_account_creation` to API', async () => {
const redirectUrl = `https://dev.va.gov/auth/login/callback/?type=logingov`;
const skipMhvAccountCreation = true;
global.window.location = `https://dev.va.gov/terms-of-use/?redirect_url=${redirectUrl}&skip_mhv_account_creation=${skipMhvAccountCreation}`;

const mockStore = store();
server.use(
rest.get(
`https://dev-api.va.gov/v0/terms_of_use_agreements/v1/latest`,
(_, res, ctx) => res(ctx.status(200)),
),
rest.post(
`https://dev-api.va.gov/v0/terms_of_use_agreements/v1/accept`,
(req, res, ctx) => {
expect(req.url.searchParams.get('skip_mhv_account_creation')).to.eql(
skipMhvAccountCreation,
);
return res(ctx.status(200), ctx.json(touResponse200));
},
),
);
const { queryAllByTestId } = render(
<Provider store={mockStore}>
<TermsOfUse />
</Provider>,
);

await waitFor(() => {
const acceptButton = queryAllByTestId('accept')[0];
expect(acceptButton).to.exist;
fireEvent.click(acceptButton);
expect(global.window.location).to.not.eql(redirectUrl);
});
});

it('should show an error state if there is a network error | non-modal', async () => {
const redirectUrl = `https://dev.va.gov/auth/login/callback/?type=idme`;
global.window.location = `https://dev.va.gov/terms-of-use/?redirect_url=${redirectUrl}`;
Expand Down
Loading