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

BNGP-4970: LPA reference data should not store in db #792

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { submitGetRequest, submitPostRequest } from '../helpers/server.js'
import constants from '../../../utils/credits-purchase-constants.js'
import lojConstants from '../../../utils/loj-constants.js'
import { getLpaNames } from '../../../utils/get-lpas.js'

jest.mock('../../../utils/get-lpas.js')

const url = constants.routes.CREDITS_PURCHASE_DEVELOPMENT_PROJECT_INFORMATION

describe(url, () => {
Expand All @@ -23,14 +26,13 @@ describe(url, () => {

redisMap = new Map()
redisMap.set(constants.redisKeys.PLANNING_AUTHORTITY_LIST, ['Planning Authority 1', 'Planning Authority 2'])
redisMap.set(lojConstants.redisKeys.REF_LPA_NAMES, ['Northumberland LPA', 'Middlesbrough LPA', 'Planning Authority 1', 'Planning Authority 2', 'Planning Authority 3'])

developmentProjectInformation = require('../../credits-purchase/development-project-information.js')

getLpaNames.mockReturnValue(['Northumberland LPA', 'Middlesbrough LPA', 'Planning Authority 1', 'Planning Authority 2', 'Planning Authority 3'])
})

describe('GET', () => {
jest.mock('../../../utils/get-lpas.js')

it(`should render the ${url.substring(1)} view`, async () => {
await submitGetRequest({ url })
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { submitGetRequest, submitPostRequest } from '../helpers/server.js'
import constants from '../../../utils/constants.js'
import lojConstants from '../../../utils/loj-constants.js'
import { getLpaNames } from '../../../utils/get-lpas.js'

jest.mock('../../../utils/get-lpas.js')

const url = constants.routes.DEVELOPER_DEVELOPMENT_PROJECT_INFORMATION

describe(url, () => {
Expand All @@ -23,14 +26,13 @@ describe(url, () => {

redisMap = new Map()
redisMap.set(constants.redisKeys.PLANNING_AUTHORTITY_LIST, ['Planning Authority 1', 'Planning Authority 2'])
redisMap.set(lojConstants.redisKeys.REF_LPA_NAMES, ['Northumberland LPA', 'Middlesbrough LPA', 'Planning Authority 1', 'Planning Authority 2', 'Planning Authority 3'])

developmentProjectInformation = require('../../developer/development-project-information.js')

getLpaNames.mockReturnValue(['Northumberland LPA', 'Middlesbrough LPA', 'Planning Authority 1', 'Planning Authority 2', 'Planning Authority 3'])
})

describe('GET', () => {
jest.mock('../../../utils/get-lpas.js')

it(`should render the ${url.substring(1)} view`, async () => {
await submitGetRequest({ url })
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { submitGetRequest, submitPostRequest } from '../helpers/server.js'
import constants from '../../../utils/constants.js'
import { getLpaNames } from '../../../utils/get-lpas.js'
import { SessionMap } from '../../../utils/sessionMap.js'

const url = constants.routes.ADD_PLANNING_AUTHORITY

jest.mock('../../../utils/get-lpas.js')

describe(url, () => {
let viewResult
let h
Expand All @@ -23,14 +27,13 @@ describe(url, () => {

redisMap.set(constants.redisKeys.APPLICATION_TYPE, constants.applicationTypes.REGISTRATION)
redisMap.set(constants.redisKeys.PLANNING_AUTHORTITY_LIST, ['Planning Authority 1', 'Planning Authority 2'])
redisMap.set(constants.redisKeys.REF_LPA_NAMES, ['Northumberland LPA', 'Middlesbrough LPA', 'Planning Authority 1', 'Planning Authority 2', 'Planning Authority 3'])

addPlanningAuthority = require('../../land/add-planning-authority.js')

getLpaNames.mockReturnValue(['Northumberland LPA', 'Middlesbrough LPA', 'Planning Authority 1', 'Planning Authority 2', 'Planning Authority 3'])
})

describe('GET', () => {
jest.mock('../../../utils/get-lpas.js')

it(`should render the ${url.substring(1)} view`, async () => {
await submitGetRequest({ url })
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import creditsConstants from '../../utils/credits-purchase-constants.js'
import constants from '../../utils/loj-constants.js'
import { getLpaNames } from '../../utils/get-lpas.js'
import {
validateIdGetSchemaOptional, getValidReferrerUrl
Expand All @@ -10,8 +9,6 @@ const handlers = {
get: (request, h) => {
const lpaNames = getLpaNames(filePathAndName)

request.yar.set(constants.redisKeys.REF_LPA_NAMES, lpaNames)

const selectedLpa = request.yar.get(creditsConstants.redisKeys.CREDITS_PURCHASE_PLANNING_AUTHORITY_LIST)
const planningApplicationRef = request.yar.get(creditsConstants.redisKeys.CREDITS_PURCHASE_PLANNING_APPLICATION_REF)
const developmentName = request.yar.get(creditsConstants.redisKeys.CREDITS_PURCHASE_DEVELOPMENT_NAME)
Expand All @@ -26,10 +23,10 @@ const handlers = {
post: (request, h) => {
const { localPlanningAuthority, planningApplicationRef, developmentName } = request.payload

const refLpaNames = request.yar.get(constants.redisKeys.REF_LPA_NAMES) ?? []
const lpaNames = getLpaNames(filePathAndName) ?? []
const selectedLpa = Array.isArray(localPlanningAuthority) ? localPlanningAuthority[0] : localPlanningAuthority

const errors = lpaErrorHandler(selectedLpa, refLpaNames)
const errors = lpaErrorHandler(selectedLpa, lpaNames)

if (!planningApplicationRef) {
errors.planningApplicationRefError = {
Expand All @@ -54,7 +51,7 @@ const handlers = {
return h.view(creditsConstants.views.CREDITS_PURCHASE_DEVELOPMENT_PROJECT_INFORMATION, {
err,
errors,
lpaNames: refLpaNames,
lpaNames,
selectedLpa,
planningApplicationRef,
developmentName
Expand Down Expand Up @@ -84,10 +81,10 @@ export default [{
/**
* Handles Local Planning Authority errors
* @param {string} selectedLpa
* @param {Array<string>} refLpaNames
* @param {Array<string>} lpaNames
* @returns {Object} Local planning authority errors object
*/
const lpaErrorHandler = (selectedLpa, refLpaNames) => {
const lpaErrorHandler = (selectedLpa, lpaNames) => {
const errors = {}

if (!selectedLpa) {
Expand All @@ -99,7 +96,7 @@ const lpaErrorHandler = (selectedLpa, refLpaNames) => {
return errors
}

if (refLpaNames.length > 0 && !refLpaNames.includes(selectedLpa)) {
if (lpaNames.length > 0 && !lpaNames.includes(selectedLpa)) {
errors.invalidLocalPlanningAuthorityError = {
text: 'Enter a valid local planning authority',
href: '#invalidLocalPlanningAuthorityError'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const handlers = {
get: (request, h) => {
const lpaNames = getLpaNames(filePathAndName)

request.yar.set(constants.redisKeys.REF_LPA_NAMES, lpaNames)

const selectedLpa = request.yar.get(constants.redisKeys.DEVELOPER_PLANNING_AUTHORITY_LIST)
const planningApplicationRef = request.yar.get(constants.redisKeys.DEVELOPER_PLANNING_APPLICATION_REF)
const developmentName = request.yar.get(constants.redisKeys.DEVELOPER_DEVELOPMENT_NAME)
Expand All @@ -25,10 +23,10 @@ const handlers = {
post: (request, h) => {
const { localPlanningAuthority, planningApplicationRef, developmentName } = request.payload

const refLpaNames = request.yar.get(constants.redisKeys.REF_LPA_NAMES) ?? []
const lpaNames = getLpaNames(filePathAndName) ?? []
const selectedLpa = Array.isArray(localPlanningAuthority) ? localPlanningAuthority[0] : localPlanningAuthority

const errors = lpaErrorHandler(selectedLpa, refLpaNames)
const errors = lpaErrorHandler(selectedLpa, lpaNames)

if (!planningApplicationRef) {
errors.planningApplicationRefError = {
Expand All @@ -53,7 +51,7 @@ const handlers = {
return h.view(constants.views.DEVELOPER_DEVELOPMENT_PROJECT_INFORMATION, {
err,
errors,
lpaNames: refLpaNames,
lpaNames,
selectedLpa,
planningApplicationRef,
developmentName
Expand Down Expand Up @@ -83,10 +81,10 @@ export default [{
/**
* Handles Local Planning Authority errors
* @param {string} selectedLpa
* @param {Array<string>} refLpaNames
* @param {Array<string>} lpaNames
* @returns {Object} Local planning authority errors object
*/
const lpaErrorHandler = (selectedLpa, refLpaNames) => {
const lpaErrorHandler = (selectedLpa, lpaNames) => {
const errors = {}

if (!selectedLpa) {
Expand All @@ -98,7 +96,7 @@ const lpaErrorHandler = (selectedLpa, refLpaNames) => {
return errors
}

if (refLpaNames.length > 0 && !refLpaNames.includes(selectedLpa)) {
if (lpaNames.length > 0 && !lpaNames.includes(selectedLpa)) {
errors.invalidLocalPlanningAuthorityError = {
text: 'Enter a valid local planning authority',
href: '#localPlanningAuthority'
Expand Down
11 changes: 5 additions & 6 deletions packages/webapp/src/routes/land/add-planning-authority.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const handlers = {
const { id } = request.query
const lpaNames = getLpaNames(filePathAndName)

request.yar.set(constants.redisKeys.REF_LPA_NAMES, lpaNames)
const legalAgreementType = getLegalAgreementDocumentType(
request.yar.get(constants.redisKeys.LEGAL_AGREEMENT_DOCUMENT_TYPE))?.toLowerCase()
const lpaList = request.yar.get(constants.redisKeys.PLANNING_AUTHORTITY_LIST)
Expand All @@ -37,7 +36,7 @@ const handlers = {
const selectedLpa = Array.isArray(localPlanningAuthority) ? localPlanningAuthority[0] : localPlanningAuthority
const lpaList = request.yar.get(constants.redisKeys.PLANNING_AUTHORTITY_LIST) ?? []
const errors = {}
const refLpaNames = request.yar.get(constants.redisKeys.REF_LPA_NAMES) ?? []
const lpaNames = getLpaNames(filePathAndName) ?? []

if (!selectedLpa) {
errors.emptyLocalPlanningAuthority = {
Expand All @@ -48,11 +47,11 @@ const handlers = {
err: Object.values(errors),
errors,
legalAgreementType,
lpaNames: refLpaNames
lpaNames
})
}

if (refLpaNames.length > 0 && !refLpaNames.includes(selectedLpa)) {
if (lpaNames.length > 0 && !lpaNames.includes(selectedLpa)) {
errors.invalidLocalPlanningAuthorityError = {
text: 'Enter a valid local planning authority',
href: '#invalidLocalPlanningAuthorityError'
Expand All @@ -61,7 +60,7 @@ const handlers = {
err: Object.values(errors),
errors,
legalAgreementType,
lpaNames: refLpaNames
lpaNames
})
}

Expand All @@ -79,7 +78,7 @@ const handlers = {
err: Object.values(duplicateError),
errors,
legalAgreementType,
lpaNames: refLpaNames
lpaNames
})
}
if (id) {
Expand Down
2 changes: 0 additions & 2 deletions packages/webapp/src/utils/loj-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ const WRITTEN_AUTHORISATION_FILE_TYPE = 'written-authorisation-file-type'
const WRITTEN_AUTHORISATION_CHECKED = 'written-authorisation-checked'
const ALL_LPA = 'all-lpa'
const PLANNING_AUTHORTITY_LIST = 'planning-authority-list'
const REF_LPA_NAMES = 'ref-lpa-names'
const LAND_OWNERSHIP_PROOFS = 'land-ownership-proofs'
const ANY_OTHER_LANDOWNERS_CHECKED = 'la-any-other-landowners-checked'
const LAND_APPLICATION_SUBMITTED = 'land-application-submitted'
Expand Down Expand Up @@ -274,7 +273,6 @@ export default {
CHECK_PLANNING_AUTHORITIES,
PLANNING_AUTHORTITY_LIST,
ALL_LPA,
REF_LPA_NAMES,
IS_ADDRESS_UK_KEY,
UK_ADDRESS_KEY,
NON_UK_ADDRESS_KEY,
Expand Down
Loading