From 81a4723c85ed4adfcbf5e340ffc257095528dadf Mon Sep 17 00:00:00 2001
From: mel-am <122634403+mel-am@users.noreply.github.com>
Date: Tue, 13 Feb 2024 12:30:56 +0000
Subject: [PATCH 1/4] add-team vaildation intergration test
---
test/integration/routes/add-team.spec.ts | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/test/integration/routes/add-team.spec.ts b/test/integration/routes/add-team.spec.ts
index 3682ef8..e02097a 100644
--- a/test/integration/routes/add-team.spec.ts
+++ b/test/integration/routes/add-team.spec.ts
@@ -12,8 +12,9 @@ import { logger } from '../../../src/middleware/logger.middleware';
import { log } from '../../../src/utils/logger';
import { authentication } from '../../../src/middleware/authentication.middleware';
-import { MOCK_REDIRECT_MESSAGE as MOCK_REDIRECT_MESSAGE, MOCK_POST_ADD_TEAM_RESPONSE, MOCK_GET_ADD_TEAM_RESPONSE } from '../../mock/text.mock';
+import { MOCK_REDIRECT_MESSAGE, MOCK_GET_ADD_TEAM_RESPONSE, MOCK_POST_ADD_TEAM_RESPONSE } from '../../mock/text.mock';
import { MOCK_POST_ADD_TEAM } from '../../mock/data';
+import { ErrorMessages } from '../../../src/validation/error.messages';
const mockedLogger = logger as jest.Mock;
mockedLogger.mockImplementation((_req: Request, _res: Response, next: NextFunction) => next());
@@ -45,13 +46,27 @@ describe('add-team endpoint integration tests', () => {
expect(mockedAuth).toHaveBeenCalledTimes(1);
});
- test('Should log the Team Name and Team Maintainer GitHub handle on POST request.', async () => {
+ test('Should render the same page with error messages after POST request', async () => {
+ const res = await request(app).post(config.ADD_TEAM_URL).send({
+ repo_name: '',
+ team_maintainer_github_handle: '',
+ });
+
+ expect(res.status).toEqual(200);
+ expect(res.text).toContain(ErrorMessages.TEAM_NAME);
+ expect(res.text).toContain(ErrorMessages.TEAM_MAINTAINER_GITHUB_HANDLE);
+ expect(res.text).toContain(MOCK_GET_ADD_TEAM_RESPONSE);
+ expect(mockedLogger).toHaveBeenCalledTimes(1);
+ expect(mockedAuth).toHaveBeenCalledTimes(1);
+ });
+
+ test('Should log the add team details POST request', async () => {
const res = await request(app).post(config.ADD_TEAM_URL).send(MOCK_POST_ADD_TEAM);
const mockLog = log.info as jest.Mock;
- expect(res.text).toContain(MOCK_REDIRECT_MESSAGE);
expect(mockLog).toBeCalledWith(MOCK_POST_ADD_TEAM_RESPONSE);
+ expect(res.text).toContain(MOCK_REDIRECT_MESSAGE);
expect(mockedLogger).toHaveBeenCalledTimes(1);
expect(mockedAuth).toHaveBeenCalledTimes(1);
});
From c3c2a310ced1d6bb5dcb3892b5feff2d2c74b8c9 Mon Sep 17 00:00:00 2001
From: mel-am <122634403+mel-am@users.noreply.github.com>
Date: Tue, 13 Feb 2024 12:32:59 +0000
Subject: [PATCH 2/4] Add add-team vaildation fields
---
src/routes/add-team.ts | 4 +++-
src/validation/add-team.validation.ts | 10 ++++++++++
src/validation/error.messages.ts | 4 +++-
3 files changed, 16 insertions(+), 2 deletions(-)
create mode 100644 src/validation/add-team.validation.ts
diff --git a/src/routes/add-team.ts b/src/routes/add-team.ts
index 5859007..19e9468 100644
--- a/src/routes/add-team.ts
+++ b/src/routes/add-team.ts
@@ -4,10 +4,12 @@ import { authentication } from '../middleware/authentication.middleware';
import { get, post } from '../controller/add-team.controller';
import * as config from '../config';
+import { addTeam } from '../validation/add-team.validation';
+import { checkValidations } from '../middleware/validation.middleware';
const addTeamRouter = Router();
addTeamRouter.get(config.ADD_TEAM_URL, authentication, get);
-addTeamRouter.post(config.ADD_TEAM_URL, authentication, post);
+addTeamRouter.post(config.ADD_TEAM_URL, authentication, ...addTeam, checkValidations, post);
export default addTeamRouter;
diff --git a/src/validation/add-team.validation.ts b/src/validation/add-team.validation.ts
new file mode 100644
index 0000000..0ef4e55
--- /dev/null
+++ b/src/validation/add-team.validation.ts
@@ -0,0 +1,10 @@
+import { body } from 'express-validator';
+
+import { ErrorMessages } from './error.messages';
+import { descriptionValidation } from './fields/description.validation';
+
+export const addTeam = [
+ body('team_name').notEmpty({ ignore_whitespace: true }).withMessage(ErrorMessages.TEAM_NAME),
+ body('team_maintainer_github_handle').not().isEmpty({ ignore_whitespace: true }).withMessage(ErrorMessages.TEAM_MAINTAINER_GITHUB_HANDLE),
+ ...descriptionValidation
+];
diff --git a/src/validation/error.messages.ts b/src/validation/error.messages.ts
index 4662481..5cef87b 100644
--- a/src/validation/error.messages.ts
+++ b/src/validation/error.messages.ts
@@ -2,5 +2,7 @@ export enum ErrorMessages {
GIT_HANDLE = 'Enter the username of your GitHub handle (aka GitHub account)',
DESCRIPTION_LENGTH = 'Description must be 1000 characters or less',
REPO_NAME = 'Enter the repository name',
- VISIBILITY = 'Select a visibility option'
+ VISIBILITY = 'Select a visibility option',
+ TEAM_MAINTAINER_GITHUB_HANDLE = 'Enter the team maintainer GitHub handle',
+ TEAM_NAME = 'Enter the team name',
}
From 643e576f8dd524933c650c00ac00fed0010dfad3 Mon Sep 17 00:00:00 2001
From: mel-am <122634403+mel-am@users.noreply.github.com>
Date: Tue, 13 Feb 2024 12:33:55 +0000
Subject: [PATCH 3/4] Update add-team view for validation
---
src/views/add-team.html | 50 ++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 23 deletions(-)
diff --git a/src/views/add-team.html b/src/views/add-team.html
index 5247ff6..cc6bcd8 100644
--- a/src/views/add-team.html
+++ b/src/views/add-team.html
@@ -1,10 +1,7 @@
{% extends "layout.html" %}
{% block beforeContent %}
- {{ govukBackLink({
- text: "Back",
- href: "/landing-page"
- }) }}
+ {% include "include/back-link.html" %}
{% endblock %}
{% block content %}
@@ -16,46 +13,53 @@ Add a GitHub Team
Github Teams can be used to manage repository permissions and mentions for groups of members.
-
From 9d629de75e0bfbde1a65fa9cd764acfbe325521f Mon Sep 17 00:00:00 2001
From: mel-am <122634403+mel-am@users.noreply.github.com>
Date: Tue, 13 Feb 2024 14:25:31 +0000
Subject: [PATCH 4/4] Update add-team.html
---
src/views/add-team.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/views/add-team.html b/src/views/add-team.html
index cc6bcd8..d85a583 100644
--- a/src/views/add-team.html
+++ b/src/views/add-team.html
@@ -36,7 +36,7 @@ Add a GitHub Team
classes: "govuk-label--m"
},
classes: "govuk-input--width-10",
- id: "team-maintainer-github-handle",
+ id: "team_maintainer_github_handle",
name: "team_maintainer_github_handle",
value: team_maintainer_github_handle
}) }}