Skip to content

Commit

Permalink
ToU - pass along skip_mhv_account_creation parameter on accept (#33008)
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyanderson authored Nov 15, 2024
1 parent cee71e9 commit da601ba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
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
terms_code: redirectLocation.searchParams.get('terms_code'),
}),
...(redirectLocation.searchParams.get('skip_mhv_account_creation') && {
// eslint-disable-next-line camelcase
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

0 comments on commit da601ba

Please sign in to comment.