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 292 add routing to the landing page #3

Closed
Closed
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
18 changes: 0 additions & 18 deletions .github/workflows/dependency-review.yml

This file was deleted.

20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# Node Webapp Template
# GitHub requests app
![Static Badge](https://img.shields.io/badge/test_coverage-%E2%89%A595%25-green)

## Overview

The following repo allows us to quickly bootstrap Node projects, using this allows us to ensure consistency across our Node repositories. It can be a starting point for the creation of RESTfull API ​or for the creation of web application with GDS GovUK frontend best practice.
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.

In the context of a web application, 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 (es. for the `/info` page we have the: `info.controller.ts` and `info.html` files if model present we will have had `info.model.ts`)

### The Model

In the model we define the interface, the data structure used to represent the data for that particular page and an array used to map back and forth information between the data saved and the `nunjucks` html view data.
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 (es. for the `/info` page we have the: `info.controller.ts` and `info.html` files if model present we will have had `info.model.ts`)

### The View

We use `Nunjucks` and `GDS` style/components, we could use the prototype if an UX team is present in loco.
We use `Nunjucks` and `GDS` style/components.

### The controller

Expand Down Expand Up @@ -75,11 +71,3 @@ This will then download the necessary dependencies, build the Docker image, and
You will be able to access it on [Localhost:3000](localhost:3000).


## ToDo

- Add API service module
- Add logging service
- Add Validation and Navigation MW
- Add Authentication MW and Session handler logic
- Update CDN origin
- Publishes the SDK on npm package registry
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
web:
container_name: web-node-prototype
container_name: github-requests-app
build:
context: .
dockerfile: ./infrastructure/docker/${NODE_ENV}/Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "poc_node_protoype",
"name": "github_requests_app",
"version": "1.0.0",
"description": "POC Node Prototype",
"description": "Github requests app",
"main": "dist/server.js",
"scripts": {
"build": "tsc && cp -r src/views dist/",
Expand Down
8 changes: 4 additions & 4 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ export const NODE_SSL_ENABLED = process.env['NODE_SSL_ENABLED'];
export const PATH_SSL_PRIVATE_KEY = process.env['PATH_SSL_PRIVATE_KEY'] || '';
export const PATH_SSL_CERTIFICATE = process.env['PATH_SSL_CERTIFICATE'] || '';

export const SERVICE_NAME = 'Node Prototype';
export const SERVICE_NAME = 'GitHub Requests Service';

// Template
export const LANDING_PAGE = 'info';
export const LANDING_PAGE = 'github-service';
export const NOT_FOUND = 'page-not-found';
export const ERROR_PAGE = 'error';

// Routing paths
export const LANDING_URL = '/info';
export const LANDING_URL = '/github-service';

export const INFO_URL = '/info';
export const GITHUB_SERIVCE_URL = '/github-service';
export const HEALTHCHECK_URL = '/healthcheck';
export const SERVICE_URL = `${BASE_URL}${LANDING_URL}`;
11 changes: 11 additions & 0 deletions src/routes/github-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Router } from 'express';

import { get, post } from '../controller/github-service.controller';
import * as config from '../config';

const githubServiceRouter = Router();

githubServiceRouter.get(config.LANDING_URL, get);
githubServiceRouter.post(config.LANDING_URL, post);

export default githubServiceRouter;
4 changes: 2 additions & 2 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Router } from 'express';

import { logger } from '../middleware/logger.middleware';
import healthcheckRouter from './healthcheck';
import infoRouter from './info';
import githubServiceRouter from './github-service';

const router = Router();

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

export default router;
11 changes: 0 additions & 11 deletions src/routes/info.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/views/info.html → src/views/github-service.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

{% block content %}
<h1 class="govuk-heading-xl">
Placeholder - Info Page
Placeholder - GitHub Service Landing Page
</h1>
{% endblock %}
{% endblock %}
10 changes: 10 additions & 0 deletions src/views/layout.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "govuk/template.njk" %}

{% from "govuk/components/footer/macro.njk" import govukFooter %}
{% from "govuk/components/phase-banner/macro.njk" import govukPhaseBanner %}
{% from "govuk/components/header/macro.njk" import govukHeader %}

{% block head %}
Expand All @@ -12,6 +13,15 @@

{% endblock %}

{% block beforeContent %}
{{ govukPhaseBanner({
tag: {
text: "Alpha"
},
html: 'This is a new service'
}) }}
{% endblock %}

{% block header %}
{{ govukHeader({
homepageUrl: "https://www.gov.uk",
Expand Down
6 changes: 3 additions & 3 deletions test/integration/controller/error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
jest.mock('../../../src/controller/info.controller');
jest.mock('../../../src/controller/github-service.controller');

import { jest, beforeEach, describe, expect, test } from '@jest/globals';
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 landingController from '../../../src/controller/github-service.controller';
import {
MOCK_NOT_FOUND_RESPONSE,
MOCK_ERROR_MESSAGE,
MOCK_SERVICE_UNAVAILABLE,
MOCK_WRONG_URL
} from '../../mock/text.mock';

const mockGet = infoController.get as jest.Mock;
const mockGet = landingController.get as jest.Mock;

describe('Error integration tests', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ 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';
import { MOCK_GET_LANDING_RESPONSE, MOCK_POST_LANDING_RESPONSE } from '../../mock/text.mock';

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

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

describe('GET tests', () => {
test('renders the info page', async () => {
const res = await request(app).get(config.INFO_URL);
test('renders the landing page', async () => {
const res = await request(app).get(config.LANDING_URL);

expect(res.status).toEqual(200);
expect(res.text).toContain(MOCK_GET_INFO_RESPONSE);
expect(res.text).toContain(MOCK_GET_LANDING_RESPONSE);
expect(mockedLogger).toHaveBeenCalledTimes(1);
});
});
describe('POST tests', () => {
test('Sends post request test', async () => {
const res = await request(app).post(config.INFO_URL);
const res = await request(app).post(config.LANDING_URL);

expect(res.status).toEqual(200);
expect(res.text).toContain(MOCK_POST_INFO_RESPONSE);
expect(res.text).toContain(MOCK_POST_LANDING_RESPONSE);
expect(mockedLogger).toHaveBeenCalledTimes(1);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/mock/text.mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const MOCK_GET_INFO_RESPONSE = 'Placeholder - Info Page';
export const MOCK_POST_INFO_RESPONSE = 'post request test';
export const MOCK_GET_LANDING_RESPONSE = 'Placeholder - GitHub Service Landing Page';
export const MOCK_POST_LANDING_RESPONSE = 'post request test';
export const MOCK_OK_RESPONSE = 'OK';
export const MOCK_NOT_FOUND_RESPONSE = 'Page not found';
export const MOCK_SERVICE_UNAVAILABLE = 'Sorry, there is a problem with the service';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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 { get, post } from '../../../src/controller/github-service.controller';
import { MOCK_POST_LANDING_RESPONSE } from '../../mock/text.mock';
import * as config from '../../../src/config';

const req = {} as Request;
Expand Down Expand Up @@ -34,6 +34,6 @@ describe('Info controller tests', () => {
post(req, res);

expect(res.send).toBeCalledTimes(1);
expect(res.send).toHaveBeenCalledWith(MOCK_POST_INFO_RESPONSE);
expect(res.send).toHaveBeenCalledWith(MOCK_POST_LANDING_RESPONSE);
});
});