Skip to content

Commit

Permalink
Merge pull request #2538 from guardian/mm/consents-complete
Browse files Browse the repository at this point in the history
Show "Subscription Confirmation" page when confirming consents
  • Loading branch information
coldlink authored Jan 23, 2024
2 parents a4dc2b8 + 0df8c70 commit a9189c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
10 changes: 3 additions & 7 deletions cypress/integration/ete/consent_token/consent_token.2.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('Consent token flow', () => {
it('redirects to the success route when supplied a valid token by a logged in user', () => {
it('shows the success page when supplied a valid token by a logged in user', () => {
cy.createTestUser({
isUserEmailValidated: true,
}).then(({ emailAddress, cookies }) => {
Expand All @@ -24,12 +24,8 @@ describe('Consent token flow', () => {
cy.visit(`/consent-token/${token}/accept`, {
failOnStatusCode: false,
});
// /consents/thank-you isn't hosted by Gateway so all we need to check
// is that the cy.visit() redirected successfully, so intercept the request
// and return a 200
cy.intercept('GET', '/consents/thank-you', (req) => {
req.reply(200);
});
cy.contains('Subscribe Confirmation');
cy.url().should('include', '/subscribe/success');
});
});
});
Expand Down
5 changes: 2 additions & 3 deletions src/server/routes/consentToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { mergeRequestState } from '@/server/lib/requestState';
import { logger } from '@/server/lib/serverSideLogger';
import { trackMetric } from '@/server/lib/trackMetric';
import { buildUrl } from '@/shared/lib/routeUtils';

// This route is of this specific form because it's a direct copy of the legacy
// route in identity-frontend, and emails sent by IDAPI contain this URL.
Expand All @@ -25,9 +26,7 @@ router.get(

trackMetric('ConsentToken::Success');

// Redirect to /consents/thank-you (a page managed by Frontend). This is
// to retain the legacy behaviour of the route from identity-frontend.
return res.redirect(303, '/consents/thank-you?useIdapi=true');
return res.redirect(303, buildUrl('/subscribe/success'));
} catch (error) {
logger.error(`${req.method} ${req.originalUrl} Error`, error, {
request_id: res.locals.requestId,
Expand Down
17 changes: 17 additions & 0 deletions src/server/routes/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,21 @@ const handler = (action: SubscriptionAction) =>
router.get('/unsubscribe/:emailType/:data/:token', handler('unsubscribe'));
router.get('/subscribe/:emailType/:data/:token', handler('subscribe'));

router.get(
'/subscribe/success',
(_: Request, res: ResponseWithRequestState) => {
// show the subscribe confirmation page
const html = renderer(`/subscribe/success`, {
requestState: mergeRequestState(res.locals, {
pageData: {
accountManagementUrl,
},
}),
pageTitle: `Subscribe Confirmation`,
});

return res.type('html').send(html);
},
);

export default router.router;

0 comments on commit a9189c3

Please sign in to comment.