From 199f673db84682006ec0649bf0e8e4797d942b37 Mon Sep 17 00:00:00 2001 From: George Goodall Date: Thu, 1 Aug 2024 14:26:29 +0100 Subject: [PATCH 1/3] updated the manage controller/route to an organisations controller and route and added a placeholder page --- ...ntroller.js => OrganisationsController.js} | 10 ++++--- src/routes/manage.js | 8 ------ src/routes/organisations.js | 10 +++++++ src/serverSetup/routes.js | 10 ++++--- src/views/organisations/find.html | 26 +++++++++++++++++++ .../overview.html} | 0 test/unit/lpaOverviewController.test.js | 2 +- test/unit/lpaOverviewPage.test.js | 2 +- 8 files changed, 51 insertions(+), 17 deletions(-) rename src/controllers/{LpaOverviewController.js => OrganisationsController.js} (90%) delete mode 100644 src/routes/manage.js create mode 100644 src/routes/organisations.js create mode 100644 src/views/organisations/find.html rename src/views/{manage/lpa-overview.html => organisations/overview.html} (100%) diff --git a/src/controllers/LpaOverviewController.js b/src/controllers/OrganisationsController.js similarity index 90% rename from src/controllers/LpaOverviewController.js rename to src/controllers/OrganisationsController.js index 497624e4..05984dd0 100644 --- a/src/controllers/LpaOverviewController.js +++ b/src/controllers/OrganisationsController.js @@ -10,7 +10,7 @@ const availableDatasets = Object.values(dataSubjects) .map(dataset => dataset.value) ) -const LpaOverviewController = { +const organisationsController = { /** * Get LPA overview data and render the overview page * @param {Request} req - Express request object @@ -63,12 +63,16 @@ const LpaOverviewController = { datasetsWithErrors } - res.render('manage/lpa-overview.html', params) + res.render('organisations/overview.html', params) } catch (error) { logger.error(error) next(error) } + }, + + async getOrganisations (req, res, next) { + res.render('organisations/find.html') } } -export default LpaOverviewController +export default organisationsController diff --git a/src/routes/manage.js b/src/routes/manage.js deleted file mode 100644 index a4cb31eb..00000000 --- a/src/routes/manage.js +++ /dev/null @@ -1,8 +0,0 @@ -import express from 'express' -import LpaOverviewController from '../controllers/LpaOverviewController.js' - -const router = express.Router() - -router.get('/:lpa/overview', LpaOverviewController.getOverview) - -export default router diff --git a/src/routes/organisations.js b/src/routes/organisations.js new file mode 100644 index 00000000..250bb13e --- /dev/null +++ b/src/routes/organisations.js @@ -0,0 +1,10 @@ +import express from 'express' +import OrganisationsController from '../controllers/OrganisationsController.js' + +const router = express.Router() + +router.get('/', OrganisationsController.getOrganisations) + +router.get('/:lpa/overview', OrganisationsController.getOverview) + +export default router diff --git a/src/serverSetup/routes.js b/src/serverSetup/routes.js index 1a4cb908..b809dbfb 100644 --- a/src/serverSetup/routes.js +++ b/src/serverSetup/routes.js @@ -3,17 +3,19 @@ import endpointSubmissionFormFormWisard from '../routes/form-wizard/endpoint-sub import accessibility from '../routes/accessibility.js' import polling from '../routes/api.js' import health from '../routes/health.js' -import manage from '../routes/manage.js' +import organisations from '../routes/organisations.js' import privacy from '../routes/privacy.js' import cookies from '../routes/cookies.js' export function setupRoutes (app) { app.use('/', checkFormWizard) app.use('/submit', endpointSubmissionFormFormWisard) - app.use('/accessibility', accessibility) + app.use('/organisations', organisations) + app.use('/api', polling) - app.use('/health', health) - app.use('/manage', manage) + + app.use('/accessibility', accessibility) app.use('/privacy-notice', privacy) app.use('/cookies', cookies) + app.use('/health', health) } diff --git a/src/views/organisations/find.html b/src/views/organisations/find.html new file mode 100644 index 00000000..c6d190d9 --- /dev/null +++ b/src/views/organisations/find.html @@ -0,0 +1,26 @@ +{% extends "layouts/main.html" %} + +{% from "govuk/components/breadcrumbs/macro.njk" import govukBreadcrumbs %} +{% from "govuk/components/tag/macro.njk" import govukTag %} + +{% block beforeContent %} +{{ super() }} + +{% endblock %} + +{% block content %} + +
+
+ +

+ {{ pageName }} +

+
+
+ +

Find page placeholder

+ + + +{% endblock %} \ No newline at end of file diff --git a/src/views/manage/lpa-overview.html b/src/views/organisations/overview.html similarity index 100% rename from src/views/manage/lpa-overview.html rename to src/views/organisations/overview.html diff --git a/test/unit/lpaOverviewController.test.js b/test/unit/lpaOverviewController.test.js index 073b5c6d..a6d90ebb 100644 --- a/test/unit/lpaOverviewController.test.js +++ b/test/unit/lpaOverviewController.test.js @@ -33,7 +33,7 @@ describe('LpaOverviewController', () => { await LpaOverviewController.getOverview(req, res, next) expect(res.render).toHaveBeenCalledTimes(1) - expect(res.render).toHaveBeenCalledWith('manage/lpa-overview.html', expect.objectContaining({ + expect(res.render).toHaveBeenCalledWith('organisations/overview.html', expect.objectContaining({ organisation: { name: 'Test LPA' }, datasets: expect.arrayContaining([ { endpoint: 'https://example.com', issue: false, error: false, slug: 'dataset1' }, diff --git a/test/unit/lpaOverviewPage.test.js b/test/unit/lpaOverviewPage.test.js index b12efc6b..1253e98d 100644 --- a/test/unit/lpaOverviewPage.test.js +++ b/test/unit/lpaOverviewPage.test.js @@ -78,7 +78,7 @@ describe('LPA Overview Page', () => { } ] } - const html = nunjucks.render('manage/lpa-overview.html', params) + const html = nunjucks.render('organisations/overview.html', params) const dom = new jsdom.JSDOM(html) const document = dom.window.document From ae7c01bcf7126682d82717c6e3dca4930ee7cb18 Mon Sep 17 00:00:00 2001 From: George Goodall Date: Thu, 1 Aug 2024 14:48:02 +0100 Subject: [PATCH 2/3] updated test file --- test/unit/lpaOverviewController.test.js | 64 ------------------- test/unit/organisationsController.test.js | 75 +++++++++++++++++++++++ 2 files changed, 75 insertions(+), 64 deletions(-) delete mode 100644 test/unit/lpaOverviewController.test.js create mode 100644 test/unit/organisationsController.test.js diff --git a/test/unit/lpaOverviewController.test.js b/test/unit/lpaOverviewController.test.js deleted file mode 100644 index a6d90ebb..00000000 --- a/test/unit/lpaOverviewController.test.js +++ /dev/null @@ -1,64 +0,0 @@ -import { describe, it, vi, expect, beforeEach } from 'vitest' -import LpaOverviewController from '../../src/controllers/LpaOverviewController.js' -import performanceDbApi from '../../src/services/performanceDbApi.js' - -vi.mock('../../src/services/performanceDbApi.js') -vi.mock('../../src/utils/utils.js', () => { - return { - dataSubjects: {} - } -}) - -describe('LpaOverviewController', () => { - beforeEach(() => { - vi.resetAllMocks() - }) - - it('should render the lpa overview page', async () => { - const req = { params: { lpa: 'test-lpa' } } - const res = { render: vi.fn() } - const next = vi.fn() - - const expectedResponse = { - name: 'Test LPA', - datasets: { - dataset1: { endpoint: 'https://example.com', issue: false, error: false }, - dataset2: { endpoint: null, issue: true, error: false }, - dataset3: { endpoint: 'https://example.com', issue: false, error: true } - } - } - - performanceDbApi.getLpaOverview = vi.fn().mockResolvedValue(expectedResponse) - - await LpaOverviewController.getOverview(req, res, next) - - expect(res.render).toHaveBeenCalledTimes(1) - expect(res.render).toHaveBeenCalledWith('organisations/overview.html', expect.objectContaining({ - organisation: { name: 'Test LPA' }, - datasets: expect.arrayContaining([ - { endpoint: 'https://example.com', issue: false, error: false, slug: 'dataset1' }, - { endpoint: null, issue: true, error: false, slug: 'dataset2' }, - { endpoint: 'https://example.com', issue: false, error: true, slug: 'dataset3' } - ]), - totalDatasets: 3, - datasetsWithEndpoints: 2, - datasetsWithIssues: 1, - datasetsWithErrors: 1 - })) - }) - - it('should catch and pass errors to the next function', async () => { - const req = { params: { lpa: 'test-lpa' } } - const res = { } - const next = vi.fn() - - const error = new Error('Test error') - - vi.mocked(performanceDbApi.getLpaOverview).mockRejectedValue(error) - - await LpaOverviewController.getOverview(req, res, next) - - expect(next).toHaveBeenCalledTimes(1) - expect(next).toHaveBeenCalledWith(error) - }) -}) diff --git a/test/unit/organisationsController.test.js b/test/unit/organisationsController.test.js new file mode 100644 index 00000000..71571568 --- /dev/null +++ b/test/unit/organisationsController.test.js @@ -0,0 +1,75 @@ +import { describe, it, vi, expect, beforeEach } from 'vitest' +import LpaOverviewController from '../../src/controllers/OrganisationsController.js' +import performanceDbApi from '../../src/services/performanceDbApi.js' + +vi.mock('../../src/services/performanceDbApi.js') +vi.mock('../../src/utils/utils.js', () => { + return { + dataSubjects: {} + } +}) + +describe('OrganisationsController.js', () => { + beforeEach(() => { + vi.resetAllMocks() + }) + + describe('overview', () => { + it('should render the overview page', async () => { + const req = { params: { lpa: 'test-lpa' } } + const res = { render: vi.fn() } + const next = vi.fn() + + const expectedResponse = { + name: 'Test LPA', + datasets: { + dataset1: { endpoint: 'https://example.com', issue: false, error: false }, + dataset2: { endpoint: null, issue: true, error: false }, + dataset3: { endpoint: 'https://example.com', issue: false, error: true } + } + } + + performanceDbApi.getLpaOverview = vi.fn().mockResolvedValue(expectedResponse) + + await LpaOverviewController.getOverview(req, res, next) + + expect(res.render).toHaveBeenCalledTimes(1) + expect(res.render).toHaveBeenCalledWith('organisations/overview.html', expect.objectContaining({ + organisation: { name: 'Test LPA' }, + datasets: expect.arrayContaining([ + { endpoint: 'https://example.com', issue: false, error: false, slug: 'dataset1' }, + { endpoint: null, issue: true, error: false, slug: 'dataset2' }, + { endpoint: 'https://example.com', issue: false, error: true, slug: 'dataset3' } + ]), + totalDatasets: 3, + datasetsWithEndpoints: 2, + datasetsWithIssues: 1, + datasetsWithErrors: 1 + })) + }) + + it('should catch and pass errors to the next function', async () => { + const req = { params: { lpa: 'test-lpa' } } + const res = { } + const next = vi.fn() + + const error = new Error('Test error') + + vi.mocked(performanceDbApi.getLpaOverview).mockRejectedValue(error) + + await LpaOverviewController.getOverview(req, res, next) + + expect(next).toHaveBeenCalledTimes(1) + expect(next).toHaveBeenCalledWith(error) + }) + }) + + describe('find', () => { + it.todo('should render the find page', () => { + + }) + + it.todo('should catch errors and pass them onto the next function') + }) + +}) From 0cf60a33067b2da7ceef0fa76439538dad52a52a Mon Sep 17 00:00:00 2001 From: George Goodall Date: Thu, 1 Aug 2024 14:48:12 +0100 Subject: [PATCH 3/3] linting --- test/unit/organisationsController.test.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/unit/organisationsController.test.js b/test/unit/organisationsController.test.js index 71571568..a36c3be7 100644 --- a/test/unit/organisationsController.test.js +++ b/test/unit/organisationsController.test.js @@ -19,7 +19,7 @@ describe('OrganisationsController.js', () => { const req = { params: { lpa: 'test-lpa' } } const res = { render: vi.fn() } const next = vi.fn() - + const expectedResponse = { name: 'Test LPA', datasets: { @@ -28,11 +28,11 @@ describe('OrganisationsController.js', () => { dataset3: { endpoint: 'https://example.com', issue: false, error: true } } } - + performanceDbApi.getLpaOverview = vi.fn().mockResolvedValue(expectedResponse) - + await LpaOverviewController.getOverview(req, res, next) - + expect(res.render).toHaveBeenCalledTimes(1) expect(res.render).toHaveBeenCalledWith('organisations/overview.html', expect.objectContaining({ organisation: { name: 'Test LPA' }, @@ -47,18 +47,18 @@ describe('OrganisationsController.js', () => { datasetsWithErrors: 1 })) }) - + it('should catch and pass errors to the next function', async () => { const req = { params: { lpa: 'test-lpa' } } const res = { } const next = vi.fn() - + const error = new Error('Test error') - + vi.mocked(performanceDbApi.getLpaOverview).mockRejectedValue(error) - + await LpaOverviewController.getOverview(req, res, next) - + expect(next).toHaveBeenCalledTimes(1) expect(next).toHaveBeenCalledWith(error) }) @@ -71,5 +71,4 @@ describe('OrganisationsController.js', () => { it.todo('should catch errors and pass them onto the next function') }) - })