diff --git a/README.md b/README.md index 31fe1af..82df8b6 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ ## Overview The GitHub request application is a tool designed to streamline and automate the process of managing and tracking request for GitHub. This includes the adding, removal or editing of members. +Each page or user interface, defined by an endpoint, is divided into three components (MVC) and as a best practice the names for the model, view and controller have, when possible, the same start name of the endpoints (e.g. for the `/confirmation` page we have the: `confirmation.controller.ts` and `confirmation.html` files. If models were present, we would have `confirmation.model.ts`) + -Each page or user interface, defined by an endpoint, is devided into three components (MVC) and as a best practice the names for the model, view and controller have, when possible, the same start name of the endpoints (e.g. for the `/info` page we have the: `info.controller.ts` and `info.html` files if models are present we would have `info.model.ts`) ### The View diff --git a/src/config/index.ts b/src/config/index.ts index 30d53be..01a0fc2 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -9,16 +9,13 @@ export const PATH_SSL_CERTIFICATE = process.env['PATH_SSL_CERTIFICATE'] || ''; export const SERVICE_NAME = 'Node Prototype'; // Template -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}`; +export const SERVICE_URL = `${BASE_URL}${CONFIRMATION_URL}`; diff --git a/src/controller/info.controller.ts b/src/controller/info.controller.ts deleted file mode 100644 index 1b318b7..0000000 --- a/src/controller/info.controller.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Request, Response } from 'express'; -import * as config from '../config'; - -export const get = (_req: Request, res: Response) => { - return res.render(config.LANDING_PAGE); -}; - -export const post = (_req: Request, res: Response) => { - return res.send('post request test'); -}; diff --git a/src/routes/index.ts b/src/routes/index.ts index 4c92a6e..41042ec 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -2,14 +2,12 @@ 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; diff --git a/src/routes/info.ts b/src/routes/info.ts deleted file mode 100644 index 17a802a..0000000 --- a/src/routes/info.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Router } from 'express'; - -import { get, post } from '../controller/info.controller'; -import * as config from '../config'; - -const infoRouter = Router(); - -infoRouter.get(config.INFO_URL, get); -infoRouter.post(config.INFO_URL, post); - -export default infoRouter; diff --git a/src/views/info.html b/src/views/info.html deleted file mode 100644 index ce80b82..0000000 --- a/src/views/info.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "layout.html" %} - -{% block content %} -

- Placeholder - Info Page -

-{% endblock %} \ No newline at end of file diff --git a/test/integration/controller/error.spec.ts b/test/integration/controller/error.spec.ts index 66d62bc..8a393dc 100644 --- a/test/integration/controller/error.spec.ts +++ b/test/integration/controller/error.spec.ts @@ -1,4 +1,4 @@ -jest.mock('../../../src/controller/info.controller'); +jest.mock('../../../src/controller/confirmation.controller'); jest.mock('../../../src/utils/logger'); import { jest, beforeEach, describe, expect, test } from '@jest/globals'; @@ -6,7 +6,7 @@ import request from 'supertest'; import app from '../../../src/app'; import * as config from '../../../src/config'; -import * as infoController from '../../../src/controller/info.controller'; +import * as confirmationController from '../../../src/controller/confirmation.controller'; import { MOCK_NOT_FOUND_RESPONSE, MOCK_ERROR_MESSAGE, @@ -14,7 +14,7 @@ import { MOCK_WRONG_URL } from '../../mock/text.mock'; -const mockGet = infoController.get as jest.Mock; +const mockGet = confirmationController.get as jest.Mock; describe('Error integration tests', () => { beforeEach(() => { @@ -32,7 +32,7 @@ describe('Error integration tests', () => { mockGet.mockImplementationOnce(() => { throw new Error(MOCK_ERROR_MESSAGE); }); - const res = await request(app).get(config.LANDING_URL); + const res = await request(app).get(config.CONFIRMATION_URL); expect(res.status).toEqual(500); expect(res.text).toContain(MOCK_SERVICE_UNAVAILABLE); diff --git a/test/integration/routes/info.spec.ts b/test/integration/routes/info.spec.ts deleted file mode 100644 index 9ec7c34..0000000 --- a/test/integration/routes/info.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -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_INFO_RESPONSE, MOCK_POST_INFO_RESPONSE } from '../../mock/text.mock'; - -const mockedLogger = logger as jest.Mock; -mockedLogger.mockImplementation((req: Request, res: Response, next: NextFunction) => next()); - -describe('Info endpoint integration tests', () => { - beforeEach(() => { - jest.clearAllMocks(); - }); - - describe('GET tests', () => { - test('renders the info page', async () => { - const res = await request(app).get(config.INFO_URL); - - expect(res.status).toEqual(200); - expect(res.text).toContain(MOCK_GET_INFO_RESPONSE); - expect(mockedLogger).toHaveBeenCalledTimes(1); - }); - }); - describe('POST tests', () => { - test('Sends post request test', async () => { - const res = await request(app).post(config.INFO_URL); - - expect(res.status).toEqual(200); - expect(res.text).toContain(MOCK_POST_INFO_RESPONSE); - expect(mockedLogger).toHaveBeenCalledTimes(1); - }); - }); -}); diff --git a/test/mock/text.mock.ts b/test/mock/text.mock.ts index 2609fc5..c50d6f8 100644 --- a/test/mock/text.mock.ts +++ b/test/mock/text.mock.ts @@ -1,5 +1,3 @@ -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'; diff --git a/test/unit/controller/info.controller.spec.ts b/test/unit/controller/info.controller.spec.ts deleted file mode 100644 index 4645147..0000000 --- a/test/unit/controller/info.controller.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { describe, expect, afterEach, test, jest } from '@jest/globals'; -import { Request, Response } from 'express'; - -import { get, post } from '../../../src/controller/info.controller'; -import { MOCK_POST_INFO_RESPONSE } from '../../mock/text.mock'; -import * as config from '../../../src/config'; - -const req = {} as Request; - -const mockResponse = () => { - const res = {} as Response; - res.render = jest.fn().mockReturnValue(res) as any; - res.send = jest.fn().mockReturnValue(res) as any; - return res; -}; - -describe('Info controller tests', () => { - afterEach(() => { - jest.resetAllMocks(); - }); - - test('should render the landing', () => { - const res = mockResponse(); - - get(req, res); - - expect(res.render).toBeCalledTimes(1); - expect(res.render).toHaveBeenCalledWith(config.LANDING_PAGE); - }); - - test('sends a post request', () => { - const res = mockResponse(); - - post(req, res); - - expect(res.send).toBeCalledTimes(1); - expect(res.send).toHaveBeenCalledWith(MOCK_POST_INFO_RESPONSE); - }); -});