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 deleted file mode 100644 index 073b5c6d..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('manage/lpa-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/lpaOverviewPage.test.js b/test/unit/lpaOverviewPage.test.js index b5923986..624f0818 100644 --- a/test/unit/lpaOverviewPage.test.js +++ b/test/unit/lpaOverviewPage.test.js @@ -81,7 +81,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 diff --git a/test/unit/organisationsController.test.js b/test/unit/organisationsController.test.js new file mode 100644 index 00000000..a36c3be7 --- /dev/null +++ b/test/unit/organisationsController.test.js @@ -0,0 +1,74 @@ +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') + }) +})