diff --git a/src/controllers/lpaDetailsController.js b/src/controllers/lpaDetailsController.js index 92f11beca..691592209 100644 --- a/src/controllers/lpaDetailsController.js +++ b/src/controllers/lpaDetailsController.js @@ -3,8 +3,11 @@ import { fetchLocalAuthorities } from '../utils/datasetteQueries/fetchLocalAutho class LpaDetailsController extends PageController { async locals (req, res, next) { - const localAuthoritiesNames = await fetchLocalAuthorities() + if (!req.sessionModel?.get('lpa') || !req.sessionModel?.get('dataset')) { + return res.redirect('/') + } + const localAuthoritiesNames = await fetchLocalAuthorities() const listItems = localAuthoritiesNames.map(name => ({ text: name, value: name diff --git a/src/routes/form-wizard/check/steps.js b/src/routes/form-wizard/check/steps.js index 1d5852089..bab185a16 100644 --- a/src/routes/form-wizard/check/steps.js +++ b/src/routes/form-wizard/check/steps.js @@ -25,7 +25,6 @@ export default { entryPoint: true, resetJourney: true, next: 'dataset', - template: 'check/start.html', noPost: true }, '/dataset': { diff --git a/src/routes/form-wizard/endpoint-submission-form/steps.js b/src/routes/form-wizard/endpoint-submission-form/steps.js index e9bbc1158..a4f8b7202 100644 --- a/src/routes/form-wizard/endpoint-submission-form/steps.js +++ b/src/routes/form-wizard/endpoint-submission-form/steps.js @@ -26,7 +26,6 @@ export default { fields: ['name', 'email'], next: 'dataset-details', controller: LpaDetailsController, - backLink: '/start', checkJourney: false }, '/dataset-details': { diff --git a/src/views/check/start.html b/src/views/check/start.html deleted file mode 100644 index 064c26fa1..000000000 --- a/src/views/check/start.html +++ /dev/null @@ -1,61 +0,0 @@ -{% from "govuk/components/button/macro.njk" import govukButton %} -{% from "govuk/components/details/macro.njk" import govukDetails %} -{% from "x-govuk/components/related-navigation/macro.njk" import xGovukRelatedNavigation %} - -{% extends "layouts/main.html" %} - -{% set serviceType = 'Check' %} -{% set pageName = 'Start' %} - -{% block content %} - - -{% set content %} - - Use this service to check your: - - - Article 4 direction data - - conservation area data - - listed building data - - tree preservation order data - - ## Before you start - - Your data must follow the [data specification](/guidance/specifications/). - - You need to choose to provide your data in one of these file formats: - - - CSV - - GeoJSON - - GML - - GeoPackage - - Alternatively you can provide us with a URL. - - - {{ govukButton({ - text: "Start now", - href: "/check/dataset", - isStartButton: true - }) }} - - -{% endset %} - -
-
-

- {{serviceName}} -

-
-
- -
-
- {{content | govukMarkdown(headingsStartWith="l") | safe}} -
-
- -
-
-{% endblock %} diff --git a/src/views/submit/start.html b/src/views/submit/start.html deleted file mode 100644 index c181abd06..000000000 --- a/src/views/submit/start.html +++ /dev/null @@ -1,72 +0,0 @@ -{% extends "layouts/main.html" %} -{% from "govuk/components/button/macro.njk" import govukButton %} -{% from "x-govuk/components/related-navigation/macro.njk" import xGovukRelatedNavigation %} - -{% set serviceType = 'Submit' %} -{% set pageName = 'Start' %} - -{% block content %} - -{% set content %} - -Use this service to submit or update: - -- Article 4 direction data -- conservation area data -- listed building data -- tree preservation order data - -## Before you start - -Your data must follow the [data specification](/guidance/specifications/). - -You need to choose to provide your data in one of these file formats: - -- CSV -- GeoJSON -- GML -- GeoPackage - -Alternatively you can provide us with a URL. - - -
- {{ govukButton({ - text: "Start now", - isStartButton: true - }) }} -
- -{% endset %} - -
-
-

- {{ serviceName }} -

-
-
- -
-
- {{content | govukMarkdown(headingsStartWith="l") | safe}} -
-
- {{ xGovukRelatedNavigation({ - sections: [{ - items: [ - { - text: "Prepare data to the specifications", - href: "/guidance/specifications/" - }, - { - text: "Publish data on your website", - href: "/guidance/publish-data-on-your-website" - } - ], - subsections: [] - }] - }) }} -
-
-{% endblock %} diff --git a/test/unit/lpaDetailsController.test.js b/test/unit/lpaDetailsController.test.js index ef6660082..d91492357 100644 --- a/test/unit/lpaDetailsController.test.js +++ b/test/unit/lpaDetailsController.test.js @@ -25,15 +25,24 @@ describe('lpaDetailsController', async () => { }) describe('locals', () => { - it('should set localAuthorities options in the form', async () => { - const req = { + let req, res, next + beforeEach(() => { + req = { form: { options: {} + }, + sessionModel: { + get: vi.fn((key) => { + if (key === 'lpa' || key === 'dataset') return 'mock-value' + return undefined + }) } } - const res = {} - const next = vi.fn() + res = { redirect: vi.fn() } + next = vi.fn() + }) + it('should set localAuthorities options in the form', async () => { const localAuthoritiesNames = ['Authority 1', 'Authority 2'] fetchLocalAuthorities.fetchLocalAuthorities = vi.fn().mockResolvedValue(localAuthoritiesNames) @@ -49,20 +58,38 @@ describe('lpaDetailsController', async () => { }) it('should call super.locals', async () => { - const req = { - form: { - options: {} - } - } - const res = {} - const next = vi.fn() - fetchLocalAuthorities.fetchLocalAuthorities = vi.fn().mockResolvedValue([]) const superLocalsSpy = vi.spyOn(PageController.prototype, 'locals') await controller.locals(req, res, next) expect(superLocalsSpy).toHaveBeenCalledWith(req, res, next) + expect(res.redirect).not.toHaveBeenCalled() + expect(next).toHaveBeenCalled() + }) + + it('should redirect when lpa is missing from session', async () => { + req.sessionModel.get = vi.fn((key) => { + if (key === 'dataset') return 'mock-value' + return undefined + }) + + await controller.locals(req, res, next) + + expect(res.redirect).toHaveBeenCalledWith('/') + expect(next).not.toHaveBeenCalled() + }) + + it('should redirect when dataset is missing from session', async () => { + req.sessionModel.get = vi.fn((key) => { + if (key === 'lpa') return 'mock-value' + return undefined + }) + + await controller.locals(req, res, next) + + expect(res.redirect).toHaveBeenCalledWith('/') + expect(next).not.toHaveBeenCalled() }) }) })