From e9e95e64640b5f8600b8ae0ef8fcb55023232b81 Mon Sep 17 00:00:00 2001 From: Daniel Murray Date: Tue, 20 Aug 2024 22:51:24 +0100 Subject: [PATCH] update collaborator endpoint to follow create/collaborator --- src/routes/github/collaborator.ts | 6 +++--- src/views/github-home.html | 2 +- test/integration/routes/github/collaborator.spec.ts | 13 ++++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/routes/github/collaborator.ts b/src/routes/github/collaborator.ts index 8adf7ed..e50f53f 100644 --- a/src/routes/github/collaborator.ts +++ b/src/routes/github/collaborator.ts @@ -9,12 +9,12 @@ import { get, getById, post, postById, removeById } from '../../controller/githu const CollaboratorRouter = Router(); -CollaboratorRouter.get(config.GITHUB_URL + config.COLLABORATOR_URL, authentication, get); -CollaboratorRouter.get(config.GITHUB_URL + config.UPDATE + config.COLLABORATOR_URL + config.PARAM_ID, authentication, getById); +CollaboratorRouter.get(config.GITHUB_URL + config.CREATE + config.COLLABORATOR_URL, authentication, get); +CollaboratorRouter.post(config.GITHUB_URL + config.CREATE + config.COLLABORATOR_URL, authentication, ...Collaborator, checkValidations, post); CollaboratorRouter.get(config.GITHUB_URL + config.REMOVE + config.COLLABORATOR_URL + config.PARAM_ID, authentication, removeById); -CollaboratorRouter.post(config.GITHUB_URL + config.COLLABORATOR_URL, authentication, ...Collaborator, checkValidations, post); +CollaboratorRouter.get(config.GITHUB_URL + config.UPDATE + config.COLLABORATOR_URL + config.PARAM_ID, authentication, getById); CollaboratorRouter.post(config.GITHUB_URL + config.UPDATE + config.COLLABORATOR_URL + config.PARAM_ID, authentication, ...Collaborator, checkValidations, postById); export default CollaboratorRouter; diff --git a/src/views/github-home.html b/src/views/github-home.html index 6ef7165..d0276d7 100644 --- a/src/views/github-home.html +++ b/src/views/github-home.html @@ -18,7 +18,7 @@

General requests

Add a new repository
  • - Add a new collaborator to a repository + Add a new collaborator to a repository
  • Additional requests

    diff --git a/test/integration/routes/github/collaborator.spec.ts b/test/integration/routes/github/collaborator.spec.ts index f3ad2e7..1df62bf 100644 --- a/test/integration/routes/github/collaborator.spec.ts +++ b/test/integration/routes/github/collaborator.spec.ts @@ -26,13 +26,16 @@ const mockedAuth = authentication as jest.Mock; mockedAuth.mockImplementation((_req: Request, _res: Response, next: NextFunction) => next()); describe('Collaborator endpoint integration tests', () => { + + const collaboratorEndpoint = config.GITHUB_URL + config.CREATE + config.COLLABORATOR_URL; + beforeEach(() => { jest.clearAllMocks(); }); describe('GET tests', () => { test('renders the collaborator page', async () => { - const res = await request(app).get(config.GITHUB_URL + config.COLLABORATOR_URL); + const res = await request(app).get(collaboratorEndpoint); expect(res.status).toEqual(200); expect(res.text).toContain(MOCK_GET_COLLABORATOR_RESPONSE); @@ -40,9 +43,9 @@ describe('Collaborator endpoint integration tests', () => { expect(mockedAuth).toHaveBeenCalledTimes(1); }); }); - describe('Add collaborator POST tests', () => { + describe('collaborator POST tests', () => { test('Should redirect to github-home page after POST request', async () => { - const res = await request(app).post(config.GITHUB_URL + config.COLLABORATOR_URL).send(MOCK_POST_COLLABORATOR); + const res = await request(app).post(collaboratorEndpoint).send(MOCK_POST_COLLABORATOR); expect(res.status).toEqual(302); expect(res.text).toContain(MOCK_GITHUB_HOME_REDIRECT_MESSAGE); @@ -51,7 +54,7 @@ describe('Collaborator endpoint integration tests', () => { }); test('Should render the same page with error messages after POST request', async () => { - const res = await request(app).post(config.GITHUB_URL + config.COLLABORATOR_URL).send({ + const res = await request(app).post(collaboratorEndpoint).send({ first_name: '', last_name: '', github_handle: '', @@ -71,7 +74,7 @@ describe('Collaborator endpoint integration tests', () => { }); test('Should log the collaborator details on POST request.', async () => { - const res = await request(app).post(config.GITHUB_URL + config.COLLABORATOR_URL).send(MOCK_POST_COLLABORATOR); + const res = await request(app).post(collaboratorEndpoint).send(MOCK_POST_COLLABORATOR); const mockLog = log.info as jest.Mock;