Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ntrnl 392 add contact us page #60

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const ADD_COLLABORATOR = 'add-collaborator';
export const CHECK_YOUR_ANSWERS = 'check-your-answers';
export const ADDITIONAL_REQUESTS = 'additional-requests';
export const COOKIES = 'cookies';
export const CONTACT_US = 'contact-us';

// Routing paths
export const START_URL = '/start';
Expand All @@ -50,6 +51,7 @@ export const ADD_COLLABORATOR_URL = '/add-collaborator';
export const CHECK_YOUR_ANSWERS_URL = '/check-your-answers';
export const ADDITIONAL_REQUESTS_URL = '/additional-requests';
export const COOKIES_URL = '/cookies';
export const CONTACT_US_URL = '/contact-us';

export const SERVICE_URL = `${BASE_URL}${HOME_URL}`;

Expand Down
6 changes: 6 additions & 0 deletions src/controller/contact-us.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.CONTACT_US);
};
12 changes: 12 additions & 0 deletions src/routes/contact-us.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Router } from 'express';

import { get } from '../controller/contact-us.controller';
import * as config from '../config';

import { authentication } from '../middleware/authentication.middleware';

const contactUsRouter = Router();

contactUsRouter.get(config.CONTACT_US_URL, authentication, get);

export default contactUsRouter;
4 changes: 3 additions & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import addTeamRouter from './add-team';
import addTeamMemberRouter from './add-team-member';
import addCollaboratorRouter from './add-collaborator';
import checkYourAnswersRouter from './check-your-answers';
import additionalRequestsRouter from './additional-requests.controller';
import additionalRequestsRouter from './additional-requests';
import cookiesRouter from './cookies';
import contactUsRouter from './contact-us';

const router = Router();

Expand All @@ -33,5 +34,6 @@ router.use(addCollaboratorRouter);
router.use(checkYourAnswersRouter);
router.use(additionalRequestsRouter);
router.use(cookiesRouter);
router.use(contactUsRouter);

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

{% block pageContent %}

<h1 class="govuk-heading-l">Contact us</h1>

<p class="govuk-body">If you need any further assistance - contact us at: [email protected]</p>

<h2 class="govuk-heading-m">Office hours</h2>

<p class="govuk-body">We can only respond to your support queries during office hours. Our office hours are 9:00am to 5:00pm, Monday to Friday.</p>

<p class="govuk-body">When you get in touch during office hours, we’ll try to reply within 5 working days.</p>

{% endblock %}
2 changes: 1 addition & 1 deletion src/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
text: "Cookies"
},
{
href: "#",
href: "/contact-us",
text: "Contact us"
},
{
Expand Down
35 changes: 35 additions & 0 deletions test/integration/routes/contact-us.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
jest.mock('../../../src/middleware/logger.middleware');
jest.mock('../../../src/middleware/authentication.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 { authentication } from '../../../src/middleware/authentication.middleware';

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

const mockedLogger = logger as jest.Mock<typeof logger>;
mockedLogger.mockImplementation((_req: Request, _res: Response, next: NextFunction) => next());
const mockedAuth = authentication as jest.Mock<typeof authentication>;
mockedAuth.mockImplementation((_req: Request, _res: Response, next: NextFunction) => next());

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

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

expect(res.text).toContain(MOCK_CONTACT_US_RESPONSE);
expect(mockedLogger).toHaveBeenCalledTimes(1);
expect(mockedAuth).toHaveBeenCalledTimes(1);
});
});
});
5 changes: 5 additions & 0 deletions test/integration/routes/cookies.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/middleware/authentication.middleware');
jest.mock('../../../src/utils/logger');

import { jest, beforeEach, describe, expect, test } from '@jest/globals';
Expand All @@ -8,11 +9,14 @@ import request from 'supertest';
import app from '../../../src/app';
import * as config from '../../../src/config';
import { logger } from '../../../src/middleware/logger.middleware';
import { authentication } from '../../../src/middleware/authentication.middleware';

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

const mockedLogger = logger as jest.Mock<typeof logger>;
mockedLogger.mockImplementation((_req: Request, _res: Response, next: NextFunction) => next());
const mockedAuth = authentication as jest.Mock<typeof authentication>;
mockedAuth.mockImplementation((_req: Request, _res: Response, next: NextFunction) => next());

describe('Cookies endpoint integration tests', () => {
beforeEach(() => {
Expand All @@ -25,6 +29,7 @@ describe('Cookies endpoint integration tests', () => {

expect(res.text).toContain(MOCK_COOKIES_RESPONSE);
expect(mockedLogger).toHaveBeenCalledTimes(1);
expect(mockedAuth).toHaveBeenCalledTimes(1);
});
});
});
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_OK_RESPONSE = 'OK';
export const MOCK_GET_CONFIRMATION_RESPONSE = 'GitHub request complete';
export const MOCK_COOKIES_RESPONSE = 'Cookies';
export const MOCK_CONTACT_US_RESPONSE = 'Contact us';
export const MOCK_GET_START_RESPONSE = 'GitHub Requests';
export const MOCK_GET_HOME_RESPONSE = 'GitHub Requests';

Expand Down
19 changes: 19 additions & 0 deletions test/unit/controller/contact-us.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, afterEach, test, jest } from '@jest/globals';

import { get } from '../../../src/controller/contact-us.controller';
import { mockRequest, mockResponse } from '../../mock/express.mock';

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

test('should render contact us template', () => {
const req = mockRequest();
const res = mockResponse();

get(req, res);

expect(res.render).toHaveBeenCalledTimes(1);
});
});
Loading