Skip to content

Commit

Permalink
chore(EMS-3533): update start url redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
ttbarnes committed Jul 16, 2024
1 parent cf74197 commit 079e422
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 15 deletions.
5 changes: 4 additions & 1 deletion e2e-tests/constants/routes/insurance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import { CHECK_YOUR_ANSWERS } from './check-your-answers';

export const MVP_INSURANCE_ROOT = '/insurance';
export const INSURANCE_ROOT = '/apply';
export const START_ROOT = '/start';

const ELIGIBILITY_ROOT = '/eligibility';

export const INSURANCE_ROUTES = {
MVP_INSURANCE_ROOT,
ROOT: INSURANCE_ROOT,
START: `${INSURANCE_ROOT}/start`,
ELIGIBILITY_ROOT,
START_ROOT,
START: `${INSURANCE_ROOT}${START_ROOT}`,
ELIGIBILITY: {
CHECK_IF_ELIGIBLE: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/check-if-eligible`,
CANNOT_APPLY: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/cannot-apply`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import { LINKS } from '../../../../../content-strings';
import { INSURANCE_ROUTES } from '../../../../../constants/routes/insurance';

const { EXTERNAL } = LINKS;

const {
ELIGIBILITY: { CHECK_IF_ELIGIBLE },
MVP_INSURANCE_ROOT,
ROOT,
START_ROOT,
} = INSURANCE_ROUTES;

const baseUrl = Cypress.config('baseUrl');

const checkIfEligibleUrl = `${baseUrl}${CHECK_IF_ELIGIBLE}`;

context(`Insurance - Redirects - '${MVP_INSURANCE_ROOT}' URLs should redirect to the '${ROOT}' equivalent URL`, () => {
describe(`/${MVP_INSURANCE_ROOT}/start`, () => {
it(`should redirect to ${EXTERNAL.FULL_APPLICATION}`, () => {
cy.navigateToUrl('/insurance/start');
describe(`${MVP_INSURANCE_ROOT}${START_ROOT}`, () => {
it(`should redirect to ${MVP_INSURANCE_ROOT}${START_ROOT}`, () => {
cy.navigateToUrl(`${MVP_INSURANCE_ROOT}${START_ROOT}`);

cy.assertUrl(EXTERNAL.FULL_APPLICATION);
cy.assertUrl(checkIfEligibleUrl);
});
});

describe(`${MVP_INSURANCE_ROOT}/eligibility/check-if-eligible`, () => {
it(`should redirect to ${CHECK_IF_ELIGIBLE}`, () => {
cy.navigateToUrl('/insurance/eligibility/check-if-eligible');

const expectedUrl = `${baseUrl}${CHECK_IF_ELIGIBLE}`;

cy.assertUrl(expectedUrl);
cy.assertUrl(checkIfEligibleUrl);
});
});
});
4 changes: 3 additions & 1 deletion src/ui/server/constants/routes/insurance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import { CHECK_YOUR_ANSWERS } from './check-your-answers';

export const MVP_INSURANCE_ROOT = '/insurance';
export const INSURANCE_ROOT = '/apply';
export const START_ROOT = '/start';

const ELIGIBILITY_ROOT = '/eligibility';

export const INSURANCE_ROUTES = {
MVP_INSURANCE_ROOT,
INSURANCE_ROOT,
ELIGIBILITY_ROOT,
START: `${INSURANCE_ROOT}/start`,
START_ROOT,
START: `${INSURANCE_ROOT}${START_ROOT}`,
ELIGIBILITY: {
CHECK_IF_ELIGIBLE: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/check-if-eligible`,
CANNOT_APPLY: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/cannot-apply`,
Expand Down
25 changes: 25 additions & 0 deletions src/ui/server/controllers/redirects/start/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import get from '.';
import { INSURANCE_ROUTES } from '../../../constants/routes/insurance';
import { Request, Response } from '../../../../types';
import { mockReq, mockRes } from '../../../test-mocks';

const {
ELIGIBILITY: { CHECK_IF_ELIGIBLE },
} = INSURANCE_ROUTES;

describe('controllers/redirects/start', () => {
let req: Request;
let res: Response;

beforeEach(() => {
req = mockReq();
res = mockRes();
});

it('should redirect to a new URL via generateRedirectUrl helper function', () => {
get(req, res);

expect(res.redirect).toHaveBeenCalledTimes(1);
expect(res.redirect).toHaveBeenCalledWith(CHECK_IF_ELIGIBLE);
});
});
17 changes: 17 additions & 0 deletions src/ui/server/controllers/redirects/start/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { INSURANCE_ROUTES } from '../../../constants/routes/insurance';
import { Request, Response } from '../../../../types';

const {
ELIGIBILITY: { CHECK_IF_ELIGIBLE },
} = INSURANCE_ROUTES;

/**
* get
* Redirect an MVP_INSURANCE_ROOT START_ROOT URL to CHECK_IF_ELIGIBLE
* @param {Express.Request} Express request
* @param {Express.Response} Express response
* @returns {Express.Response.redirect}
*/
const get = (req: Request, res: Response) => res.redirect(CHECK_IF_ELIGIBLE);

export default get;
6 changes: 4 additions & 2 deletions src/ui/server/routes/redirects/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { get, post } from '../../test-mocks/mock-router';
import { INSURANCE_ROUTES } from '../../constants/routes/insurance';
import startRedirectGet from '../../controllers/redirects/start';
import redirectGet from '../../controllers/redirects';

const { MVP_INSURANCE_ROOT } = INSURANCE_ROUTES;
const { MVP_INSURANCE_ROOT, START_ROOT } = INSURANCE_ROUTES;

describe('routes/redirects', () => {
beforeEach(() => {
Expand All @@ -14,9 +15,10 @@ describe('routes/redirects', () => {
});

it('should setup all routes', () => {
expect(get).toHaveBeenCalledTimes(2);
expect(get).toHaveBeenCalledTimes(3);
expect(post).toHaveBeenCalledTimes(0);

expect(get).toHaveBeenCalledWith(`${MVP_INSURANCE_ROOT}${START_ROOT}`, startRedirectGet);
expect(get).toHaveBeenCalledWith(`${MVP_INSURANCE_ROOT}/:referenceNumber/*`, redirectGet);
expect(get).toHaveBeenCalledWith(`${MVP_INSURANCE_ROOT}*`, redirectGet);
});
Expand Down
4 changes: 3 additions & 1 deletion src/ui/server/routes/redirects/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import express from 'express';
import { INSURANCE_ROUTES } from '../../constants/routes/insurance';
import startRedirectGet from '../../controllers/redirects/start';
import redirectGet from '../../controllers/redirects';

const { MVP_INSURANCE_ROOT } = INSURANCE_ROUTES;
const { MVP_INSURANCE_ROOT, START_ROOT } = INSURANCE_ROUTES;

// @ts-ignore
const redirectRouter = express.Router();

redirectRouter.get(`${MVP_INSURANCE_ROOT}${START_ROOT}`, startRedirectGet);
redirectRouter.get(`${MVP_INSURANCE_ROOT}/:referenceNumber/*`, redirectGet);
redirectRouter.get(`${MVP_INSURANCE_ROOT}*`, redirectGet);

Expand Down

0 comments on commit 079e422

Please sign in to comment.