Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/controllers/lpaDetailsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/routes/form-wizard/check/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default {
entryPoint: true,
resetJourney: true,
next: 'dataset',
template: 'check/start.html',
noPost: true
},
'/dataset': {
Expand Down
1 change: 0 additions & 1 deletion src/routes/form-wizard/endpoint-submission-form/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default {
fields: ['name', 'email'],
next: 'dataset-details',
controller: LpaDetailsController,
backLink: '/start',
checkJourney: false
},
'/dataset-details': {
Expand Down
61 changes: 0 additions & 61 deletions src/views/check/start.html

This file was deleted.

72 changes: 0 additions & 72 deletions src/views/submit/start.html

This file was deleted.

51 changes: 39 additions & 12 deletions test/unit/lpaDetailsController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
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)
Expand All @@ -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()
})
})
})