Skip to content

Commit

Permalink
Merge branch 'release-3.0' into feature/FCRM-5441
Browse files Browse the repository at this point in the history
  • Loading branch information
teddmason committed Jan 23, 2025
2 parents ca0c40a + c4eee7b commit 810cf69
Show file tree
Hide file tree
Showing 46 changed files with 822 additions and 282 deletions.
15 changes: 15 additions & 0 deletions __mocks__/@esri/arcgis-rest-feature-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let expectedParameters
const queryFeatureSpy = {
expectParameters: (params) => { expectedParameters = params }
}

const queryFeatures = async (requestObject) => {
if (expectedParameters) {
expect(requestObject).toEqual(expectedParameters)
}
return {
features: 'QUERY_FEATURES_RESPONSE'
}
}

module.exports = { queryFeatures, queryFeatureSpy }
17 changes: 17 additions & 0 deletions __mocks__/@esri/arcgis-rest-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

const response = {
token: 'TEST_TOKEN',
refreshToken: () => {
response.token = 'REFRESHED_TOKEN'
return response.token
}
}
const _invalidateToken = () => { response.token = undefined }

const _resetToken = () => { response.token = 'TEST_TOKEN' }

const ApplicationCredentialsManager = {
fromCredentials: () => (response)
}

module.exports = { ApplicationCredentialsManager, _invalidateToken, _resetToken }
23 changes: 18 additions & 5 deletions client/js/defra-map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,20 @@ const surfaceWaterStyleLayers = [
// 'Risk of Flooding from Surface Water Depth CCSW1 > 900mm/1',
// 'Risk of Flooding from Surface Water Depth CCSW1 > 1200mm/1'
// ]

const fixLocalStorage = () => {
// Temp fix until 0.5.0
// Map will not load if localStorage basemap is not one of default OR dark
// but 0.3.0 sets the value to 'default,light', which screws up
// the map component after an upgrade to 0.4.0
const basemap = window.localStorage.getItem('basemap')
if (basemap !== 'default' && basemap !== 'dark') {
window.localStorage.removeItem('basemap')
}
}

getDefraMapConfig().then((defraMapConfig) => {
fixLocalStorage() // Temp fix until 0.5.0
const getVectorTileUrl = (layerName) => `${defraMapConfig.agolVectorTileUrl}/${layerName + defraMapConfig.layerNameSuffix}/VectorTileServer`
const getFeatureLayerUrl = (layerName) => `${defraMapConfig.agolServiceUrl}/${layerName}/FeatureServer`
const getModelFeatureLayerUrl = (layerName) => `${defraMapConfig.agolServiceUrl}/${layerName + defraMapConfig.layerNameSuffix}/FeatureServer`
Expand Down Expand Up @@ -364,7 +377,7 @@ getDefraMapConfig().then((defraMapConfig) => {
maxZoom: 20,
centre: [340367, 322766],
height: '100%',
hasGeoLocation: true,
hasGeoLocation: false,
framework: 'esri',
symbols: [symbols.waterStorageAreas, symbols.floodDefences, symbols.mainRivers],
requestCallback: getRequest,
Expand All @@ -387,7 +400,7 @@ getDefraMapConfig().then((defraMapConfig) => {
keyDisplay: 'min',
segments: [{
heading: 'Datasets',
collapse: 'collapse',
collapse: 'expanded',
items: [
{
id: 'fz',
Expand Down Expand Up @@ -570,7 +583,7 @@ getDefraMapConfig().then((defraMapConfig) => {
{
heading: 'Map features',
parentIds: ['fz'],
collapse: 'collapse',
collapse: 'expanded',
items: [
keyItemDefinitions.floodZone1,
keyItemDefinitions.floodZone2,
Expand All @@ -582,7 +595,7 @@ getDefraMapConfig().then((defraMapConfig) => {
{
heading: 'Map features',
parentIds: ['rsd', 'rsu', 'sw'],
collapse: 'collapse',
collapse: 'expanded',
items: [
keyItemDefinitions.floodExtents,
keyItemDefinitions.waterStorageAreas,
Expand All @@ -593,7 +606,7 @@ getDefraMapConfig().then((defraMapConfig) => {
{
heading: 'Map features',
parentIds: ['mo'],
collapse: 'collapse',
collapse: 'expanded',
items: [
keyItemDefinitions.waterStorageAreas,
keyItemDefinitions.floodDefences,
Expand Down
3 changes: 2 additions & 1 deletion config/.env-example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ENV=dev
HOST=0.0.0.0
PORT=8050
fmpAppType=internal
CONNECTIONSTRING=http://dummyuri
ERRBIT_POST_ERRORS=false
ERRBIT_KEY=replace_this
Expand All @@ -19,7 +20,7 @@ ordnanceSurveyOsClientId=replace_this
ordnanceSurveyOsClientSecret=replace_this
ordnanceSurveyOsMapsKey=replace_this
siteUrl=http://dummyuri
functionAppUrl==http://dummyuri
functionAppUrl=http://dummyuri
ignoreUseAutomatedService=true
placeApiUrl=http://dummyuri
#AGOL
Expand Down
3 changes: 2 additions & 1 deletion config/__tests__/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Ensure config is correct', () => {
const { config } = require('../index')
const expectedConfig = {
env: 'dev',
appType: 'internal',
server: { port: '8050' },
geoserver: 'http://dummyuri',
views: { isCached: false },
Expand All @@ -28,7 +29,7 @@ describe('Ensure config is correct', () => {
osClientSecret: 'replace_this'
},
siteUrl: 'http://dummyuri',
functionAppUrl: '=http://dummyuri',
functionAppUrl: 'http://dummyuri',
ignoreUseAutomatedService: true,
placeApi: { url: 'http://dummyuri' },
agol: {
Expand Down
1 change: 1 addition & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require('./environment')

const config = {
env: process.env.ENV,
appType: process.env.fmpAppType,
server: {
port: process.env.PORT
},
Expand Down
1 change: 1 addition & 0 deletions config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const serverSchema = Joi.object()

const schema = Joi.object({
env: Joi.string().required(),
appType: Joi.string().required().allow('internal', 'public'),
server: serverSchema,
geoserver: Joi.string().uri().required(),
logging: Joi.object(),
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.25.9",
"@defra/flood-map": "^0.3.0",
"@defra/flood-map": "^0.4.0",
"@esri/arcgis-rest-feature-service": "^4.0.6",
"@esri/arcgis-rest-request": "^4.2.3",
"@hapi/boom": "^9.1.4",
Expand Down
21 changes: 14 additions & 7 deletions server/__test-helpers__/copy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@

const assertCopy = (selector, expectedCopy) => {
const element = document.querySelector(selector)
if (expectedCopy) {
try {
const element = document.querySelector(selector)
if (expectedCopy) {
// the REGEX trims all whitespace and only compares the actual text that will be rendered
expect(element.textContent.replace(/\s\s+/g, ' ').trim())
.toContain(expectedCopy.replace(/\s\s+/g, ' ').trim())
} else {
expect(element).toBeNull()
expect(element.textContent.replace(/\s\s+/g, ' ').trim())
.toContain(expectedCopy.replace(/\s\s+/g, ' ').trim())
} else {
expect(element).toBeNull()
}
} catch (error) {
// This Assert only runs when the expected assert fails.
// It is added as the exact location of the failure is hard to infer, when a fail occurs
// and this helps give a more meaningful failure message.
const failMessage = `expected selector ${selector} to contain ${expectedCopy || 'NO CONTENT'}`
expect(failMessage).toBeNull()
}
}

Expand Down
2 changes: 2 additions & 0 deletions server/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const HOME = 'home'
const TRIAGE = 'triage'
const ABOUT_MAP = 'about-map'
const LOCATION = 'location'
const ENGLAND_ONLY = 'england-only'
const MAP = 'map'
const RESULTS = 'results'
const CONTACT = 'contact'
Expand All @@ -18,6 +19,7 @@ const views = {
TRIAGE,
ABOUT_MAP,
LOCATION,
ENGLAND_ONLY,
MAP,
RESULTS,
CONTACT,
Expand Down
1 change: 1 addition & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async function createServer () {
await server.register(require('./plugins/error-pages'))
await server.register(require('blipp'))
await server.register(require('./plugins/full-url'))
await server.register(require('./plugins/register-cookie'))

server.ext('onPreResponse', async (request, h) => {
request.response.header('cache-control', 'no-cache')
Expand Down
9 changes: 4 additions & 5 deletions server/plugins/register-cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ const { config } = require('../../config')
exports.plugin = {
name: 'register-cookie',
register: (server, options) => {
// Cookie used to notify the client
// browser that the download is complete
server.state('pdf-download', {
ttl: 10000,
// Cookie used to store a successful p4 request to stop duplication
server.state('p4Request', {
ttl: null, // ttl is session
isSecure: config.siteUrl.startsWith('https'),
path: '/',
isSameSite: false,
isHttpOnly: true,
encoding: 'none',
encoding: 'base64json',
clearInvalid: true,
strictHeader: true
})
Expand Down
Loading

0 comments on commit 810cf69

Please sign in to comment.