Skip to content

Commit

Permalink
Merge pull request #4 from cabinetoffice/NTRNL-299-add-confirmation-page
Browse files Browse the repository at this point in the history
Ntrnl 299 add confirmation page
  • Loading branch information
harley-harris authored Jan 18, 2024
2 parents 6ea8f70 + 24d0c36 commit 1725800
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ export const SERVICE_NAME = 'Node Prototype';
export const LANDING_PAGE = 'info';
export const NOT_FOUND = 'page-not-found';
export const ERROR_PAGE = 'error';
export const CONFIRMATION = 'confirmation';

// Routing paths
export const LANDING_URL = '/info';

export const INFO_URL = '/info';
export const HEALTHCHECK_URL = '/healthcheck';
export const CONFIRMATION_URL = '/confirmation';
export const SERVICE_URL = `${BASE_URL}${LANDING_URL}`;

6 changes: 6 additions & 0 deletions src/controller/confirmation.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Request, Response } from 'express';
import * as config from '../config';

export const get = (_req: Request, res: Response) => {
return res.render(config.CONFIRMATION);
};
10 changes: 10 additions & 0 deletions src/routes/confirmation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from 'express';

import { get } from '../controller/confirmation.controller';
import * as config from '../config';

const confirmationRouter = Router();

confirmationRouter.get(config.CONFIRMATION_URL, get);

export default confirmationRouter;
2 changes: 2 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { Router } from 'express';
import { logger } from '../middleware/logger.middleware';
import healthcheckRouter from './healthcheck';
import infoRouter from './info';
import confirmationRouter from './confirmation';

const router = Router();

router.use(logger);
router.use(healthcheckRouter);
router.use(infoRouter);
router.use(confirmationRouter);

export default router;
29 changes: 29 additions & 0 deletions src/views/confirmation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "layout.html" %}

{% set mainClasses = "govuk-main-wrapper--l" %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{{ govukPanel({
titleText: "GitHub request complete",
html: "Your reference number<br><strong>987654321</strong>"
}) }}

<p class="govuk-body">We have sent you a confirmation email.</p>

<h2 class="govuk-heading-m">What happens next</h2>

<p class="govuk-body">
We’ve sent your request to cabinetoffice internal developer platform.
</p>
<p class="govuk-body">
They will contact you either to confirm your request, or to ask for more information.
</p>

<p class="govuk-body">
<a href="#" class="govuk-link">What did you think of this service?</a> (takes 30 seconds)
</p>
</div>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions src/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{% from "govuk/components/footer/macro.njk" import govukFooter %}
{% from "govuk/components/header/macro.njk" import govukHeader %}
{% from "govuk/components/panel/macro.njk" import govukPanel %}

{% block head %}

Expand Down
1 change: 1 addition & 0 deletions test/integration/controller/error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jest.mock('../../../src/controller/info.controller');
jest.mock('../../../src/utils/logger');

import { jest, beforeEach, describe, expect, test } from '@jest/globals';
import request from 'supertest';
Expand Down
31 changes: 31 additions & 0 deletions test/integration/routes/confirmation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
jest.mock('../../../src/middleware/logger.middleware');
jest.mock('../../../src/utils/logger');

import { jest, beforeEach, describe, expect, test } from '@jest/globals';
import { Request, Response, NextFunction } from 'express';
import request from 'supertest';

import app from '../../../src/app';
import * as config from '../../../src/config';
import { logger } from '../../../src/middleware/logger.middleware';

import { MOCK_GET_CONFIRMATION_RESPONSE } from '../../mock/text.mock';

const mockedLogger = logger as jest.Mock<typeof logger>;
mockedLogger.mockImplementation((req: Request, res: Response, next: NextFunction) => next());

describe('Confirmation endpoint integration tests', () => {
beforeEach(() => {
jest.clearAllMocks();
});

describe('GET tests', () => {
test('should render confirmation template', async () => {
const res = await request(app).get(config.CONFIRMATION_URL);

expect(res.status).toEqual(200);
expect(res.text).toContain(MOCK_GET_CONFIRMATION_RESPONSE);
expect(mockedLogger).toHaveBeenCalledTimes(1);
});
});
});
1 change: 1 addition & 0 deletions test/integration/routes/healthcheck.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jest.mock('../../../src/middleware/logger.middleware');
jest.mock('../../../src/utils/logger');

import { jest, beforeEach, describe, expect, test } from '@jest/globals';
import { Request, Response, NextFunction } from 'express';
Expand Down
1 change: 1 addition & 0 deletions test/integration/routes/info.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jest.mock('../../../src/middleware/logger.middleware');
jest.mock('../../../src/utils/logger');

import { jest, beforeEach, describe, expect, test } from '@jest/globals';
import { Request, Response, NextFunction } from 'express';
Expand Down
1 change: 1 addition & 0 deletions test/mock/text.mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const MOCK_GET_INFO_RESPONSE = 'Placeholder - Info Page';
export const MOCK_POST_INFO_RESPONSE = 'post request test';
export const MOCK_OK_RESPONSE = 'OK';
export const MOCK_GET_CONFIRMATION_RESPONSE = 'GitHub request complete';
export const MOCK_NOT_FOUND_RESPONSE = 'Page not found';
export const MOCK_SERVICE_UNAVAILABLE = 'Sorry, there is a problem with the service';
export const MOCK_SERVER_ERROR = 'Pipe 3000 requires elevated privileges';
Expand Down
27 changes: 27 additions & 0 deletions test/unit/controller/confirmation.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, afterEach, test, jest } from '@jest/globals';
import { Request, Response } from 'express';

import { get } from '../../../src/controller/confirmation.controller';
import * as config from '../../../src/config';

const req = {} as Request;

const mockResponse = () => {
const res = {} as Response;
res.render = jest.fn().mockReturnValue(res) as any;
return res;
};

describe('Confirmation controller test suites', () => {
afterEach(() => {
jest.resetAllMocks();
});

test('should render confirmation template', () => {
const res = mockResponse();

get(req, res);

expect(res.render).toHaveBeenCalledWith(config.CONFIRMATION);
});
});

0 comments on commit 1725800

Please sign in to comment.