Skip to content

Commit

Permalink
use new 'serviceNames' configuration object
Browse files Browse the repository at this point in the history
Seems like we're passing 'serviceName' to nunjucks in a lot of places
for no reason - we already use `getFullServiceName()` to map a
short service name (called 'serviceType' in the templates) to a full
service name. Switching to a map of service names allows us to skip
passing the service name explicitly.
  • Loading branch information
rosado committed Aug 7, 2024
1 parent ddf9f6c commit 2d8adcf
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 19 deletions.
9 changes: 8 additions & 1 deletion config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ aws: {
}
# ToDo: url and name might need updating
url: 'https://check-planning.data.gov.uk'
serviceName: 'Provide planning and housing data for England'
# NOTE: this property is deprecated, use serviceNames instead
serviceName: 'Submit and update your planning data'
# NOTE: the keys in this map are sometimes referred to as "serviceType" in the templates
serviceNames: {
submit: 'Submit and update your planning data',
check: 'Check planning and housing data for England',
manage: 'Manage planning and housing data for England'
}
feedbackLink: 'https://docs.google.com/forms/d/e/1FAIpQLSdYXqY0Aaket9XJBiGDhSL_CD_cxHZxgvQCFZZtdURdvvIY5A/viewform'
email: {
templates: {
Expand Down
15 changes: 11 additions & 4 deletions config/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import _ from 'lodash'
import yaml from 'js-yaml'
import * as v from 'valibot'

const NonEmptyString = v.pipe(v.string(), v.nonEmpty())

export const ConfigSchema = v.object({
port: v.pipe(v.integer(), v.minValue(1)),
asyncRequestApi: v.object({
url: v.url(),
port: v.pipe(v.integer(), v.minValue(1)),
requestsEndpoint: v.pipe(v.string(), v.nonEmpty()),
requestsEndpoint: NonEmptyString,
requestTimeout: v.number()
}),
maintenance: v.object({
serviceUnavailable: v.boolean(),
upTime: v.pipe(v.string(), v.nonEmpty())
upTime: NonEmptyString
}),
aws: v.object({
region: v.string(),
Expand All @@ -23,12 +25,17 @@ export const ConfigSchema = v.object({
redis: v.optional(
v.object({
secure: v.boolean(),
host: v.pipe(v.string(), v.nonEmpty()),
host: NonEmptyString,
port: v.number()
})
),
url: v.url(),
serviceName: v.pipe(v.string(), v.nonEmpty()),
serviceName: NonEmptyString,
serviceNames: v.object({
provide: NonEmptyString,
submit: NonEmptyString,
manage: NonEmptyString,
}),
feedbackLink: v.url(),
email: v.object({
templates: v.object({
Expand Down
16 changes: 13 additions & 3 deletions src/filters/getFullServiceName.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { type } from 'os'
import config from '../../config/index.js'

/*
* Get the full service name from the short service name.
*
* The names should be specified in the config under 'serviceNames'.
*
* @param {string} service
* @returns {string}
*/
export default (service) => {
const serviceName = config.serviceName

return serviceName.replace('Provide', service)
if (typeof service !== 'string') {
throw new TypeError('Service must be a string')
}
return config.serviceNames[service.toLowerCase()] || service
}
2 changes: 1 addition & 1 deletion src/routes/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ router.get('/', async (req, res) => {
}

const toReturn = {
name: config.serviceName,
name: config.serviceNames['submit'],
environment: config.environment,
version: process.env.GIT_COMMIT || 'unknown',
maintenance: config.maintenance.serviceUnavailable,
Expand Down
2 changes: 1 addition & 1 deletion src/serverSetup/nunjucks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function setupNunjucks ({ app, dataSubjects }) {
})

const globalValues = {
serviceName: config.serviceName,
serviceName: config.serviceNames['submit'],
feedbackLink: config.feedbackLink
}

Expand Down
1 change: 0 additions & 1 deletion test/unit/check-answers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('check-answers View', async () => {

runGenericPageTests(html, {
pageTitle: 'Check your answers - Check planning and housing data for England',
serviceName: config.serviceName
})

it('should render the lpa selected', () => {
Expand Down
1 change: 0 additions & 1 deletion test/unit/check/confirmationPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('Check confirmation View', () => {

runGenericPageTests(html, {
pageTitle: 'A Mock dataset submitted - Submit and update your planning data',
serviceName: config.serviceName
})

it('should render the gov uk panel', () => {
Expand Down
1 change: 0 additions & 1 deletion test/unit/choose-datasetPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('choose dataset View', () => {

runGenericPageTests(html, {
pageTitle: 'Choose dataset - Submit and update your planning data',
serviceName: config.serviceName
})

it('should display an error message when the dataset field is empty', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/dataset-details.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('dataset details View', () => {
const datasetName = mockDataSubjects.mockDataset.dataSets[0].text
runGenericPageTests(html, {
pageTitle: `Enter ${datasetName.toLowerCase()} details - Submit and update your planning data`,
serviceName: config.serviceName
serviceName: config.serviceNames['submit']
})

it('should render the correct header', () => {
Expand Down
1 change: 0 additions & 1 deletion test/unit/endpointSubmissionForm/confirmationPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('Submit confirmation View', () => {

runGenericPageTests(html, {
pageTitle: 'A Mock dataset submitted - Submit and update your planning data',
serviceName: config.serviceName
})

it('should render the gov uk panel', () => {
Expand Down
1 change: 0 additions & 1 deletion test/unit/lpa-detailsPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('Lpa-details View', () => {

runGenericPageTests(htmlNoErrors, {
pageTitle: 'Enter LPA details - Submit and update your planning data',
serviceName: config.serviceName
})

describe('validation errors', () => {
Expand Down
2 changes: 0 additions & 2 deletions test/unit/lpaOverviewPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('LPA Overview Page', () => {
organisation: {
name: 'mock org'
},
serviceName: config.serviceName,
datasetsWithEndpoints: 2,
totalDatasets: 8,
datasetsWithErrors: 2,
Expand Down Expand Up @@ -85,7 +84,6 @@ describe('LPA Overview Page', () => {

runGenericPageTests(html, {
pageTitle: 'mock org overview - Manage planning and housing data for England',
serviceName: config.serviceName
})

const statsBoxes = document.querySelector('.dataset-status').children
Expand Down
1 change: 0 additions & 1 deletion test/unit/startPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ describe('Start View', () => {

runGenericPageTests(html, {
// we skip pageTitle since this is the main page, and service name alone is sufficient
serviceName: config.serviceName
})
})

0 comments on commit 2d8adcf

Please sign in to comment.