diff --git a/src/applications/terms-of-use/containers/TermsOfUse.jsx b/src/applications/terms-of-use/containers/TermsOfUse.jsx index f2b65408926c..429467092178 100644 --- a/src/applications/terms-of-use/containers/TermsOfUse.jsx +++ b/src/applications/terms-of-use/containers/TermsOfUse.jsx @@ -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); @@ -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', diff --git a/src/applications/terms-of-use/tests/TermsOfUse.unit.spec.jsx b/src/applications/terms-of-use/tests/TermsOfUse.unit.spec.jsx index 3aada529da40..ec284217cb21 100644 --- a/src/applications/terms-of-use/tests/TermsOfUse.unit.spec.jsx +++ b/src/applications/terms-of-use/tests/TermsOfUse.unit.spec.jsx @@ -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( + + + , + ); + + 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}`;