Skip to content

Commit

Permalink
FSR-607: Sync height data for NRW stations on list and map tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyurx11 committed Aug 14, 2024
1 parent 438b845 commit 15a2a1a
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/models/views/river-and-sea-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function getStationGroup (station) {
}

function getDisplayData (station) {
return !(station.status === 'Suspended' || station.status === 'Closed' || station.value === null || station.value_erred === true || station.iswales)
return !(station.status === 'Suspended' || station.status === 'Closed' || station.value === null || station.value_erred === true)
}

function calcDistance (station, place) {
Expand Down
44 changes: 44 additions & 0 deletions test/data/chesterGetJson.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"authenticationResultCode": "ValidCredentials",
"brandLogoUri": "http://dev.virtualearth.net/Branding/logo_powered_by.png",
"copyright": "Copyright",
"resourceSets": [
{
"estimatedTotal": 1,
"resources": [
{
"__type": "Location:http://schemas.microsoft.com/search/local/ws/rest/v1",
"bbox": [53.167, -2.93, 53.25, -2.84],
"name": "Chester, Cheshire West and Chester",
"point": {
"type": "Point",
"coordinates": [53.20, -2.89]
},
"address": {
"adminDistrict": "England",
"adminDistrict2": "Cheshire West and Chester",
"countryRegion": "United Kingdom",
"formattedAddress": "Chester, Cheshire West and Chester",
"locality": "Chester",
"countryRegionIso2": "GB"
},
"confidence": "Medium",
"entityType": "PopulatedPlace",
"geocodePoints": [
{
"type": "Point",
"coordinates": [53.20, -2.89],
"calculationMethod": "Rooftop",
"usageTypes": ["Display"]
}
],
"matchCodes": ["Good"]
}
]
}
],
"statusCode": 200,
"statusDescription": "OK",
"traceId": "trace-id"
}

63 changes: 62 additions & 1 deletion test/models/river-and-sea-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const lab = exports.lab = Lab.script()
const sinon = require('sinon')
const { referencedStationViewModel, placeViewModel } = require('../../server/models/views/river-and-sea-levels')
const { referencedStationViewModel, placeViewModel, riverViewModel } = require('../../server/models/views/river-and-sea-levels')
const data = require('../data')

lab.experiment('river-and-sea-levels model test', () => {
Expand Down Expand Up @@ -106,4 +106,65 @@ lab.experiment('river-and-sea-levels model test', () => {
Code.expect(result.displayGetWarningsLink).to.equal(true)
})
})
lab.experiment('riverViewModel', () => {
lab.test('should set displayData to true for active Welsh stations', async () => {
const stations = [{
status: 'Active',
value: 1.2,
value_erred: false,
iswales: true,
lon: 0,
lat: 0,
external_name: 'Test Station',
station_type: 'R',
river_qualified_name: 'Test River',
trend: 'steady',
percentile_5: '1.0',
percentile_95: '0.5',
value_timestamp: '2022-03-30T12:00:00Z'
}]
const result = riverViewModel(stations)
Code.expect(result.stations[0].displayData).to.equal(true)
})

lab.test('should set displayData to false for suspended Welsh stations', async () => {
const stations = [{
status: 'Suspended',
value: 1.2,
value_erred: false,
iswales: true,
lon: 0,
lat: 0,
external_name: 'Test Station',
station_type: 'R',
river_qualified_name: 'Test River',
trend: 'steady',
percentile_5: '1.0',
percentile_95: '0.5',
value_timestamp: '2022-03-30T12:00:00Z'
}]
const result = riverViewModel(stations)
Code.expect(result.stations[0].displayData).to.equal(false)
})

lab.test('should set displayData to false for closed Welsh stations', async () => {
const stations = [{
status: 'Closed',
value: 1.2,
value_erred: false,
iswales: true,
lon: 0,
lat: 0,
external_name: 'Test Station',
station_type: 'R',
river_qualified_name: 'Test River',
trend: 'steady',
percentile_5: '1.0',
percentile_95: '0.5',
value_timestamp: '2022-03-30T12:00:00Z'
}]
const result = riverViewModel(stations)
Code.expect(result.stations[0].displayData).to.equal(false)
})
})
})
48 changes: 48 additions & 0 deletions test/routes/river-and-sea-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -1335,4 +1335,52 @@ lab.experiment('Test - /river-and-sea-levels', () => {

Code.expect(response.statusCode).to.equal(200)
})
lab.test('GET /river-and-sea-levels should display height, trend, and state data for Natural Resources Wales stations', async () => {
stubs.getJson.callsFake(() => require('../data/chesterGetJson.json'))
stubs.getIsEngland.callsFake(() => ({ is_england: true }))
stubs.getStationsWithin.callsFake(() => [
{
river_id: 'river-alyn',
river_name: 'Alyn',
navigable: true,
view_rank: 1,
rank: '1',
rloi_id: 4243,
up: null,
down: null,
telemetry_id: '5678',
region: 'Wales',
catchment: 'Dee',
wiski_river_name: 'River Alyn',
agency_name: 'Pontblyddyn',
external_name: 'Pontblyddyn',
station_type: 'S',
status: 'Active',
qualifier: 'u',
iswales: true,
value: '0.73',
value_timestamp: '2022-06-10T09:15:00.000Z',
value_erred: false,
trend: 'steady',
percentile_5: '1.00',
percentile_95: '0.50',
centroid: '0101000020E6100000068A4FA62670FCBF9C9AE66602264A40',
lon: -3.067,
lat: 53.154,
state: 'NORMAL'
}
])

const options = {
method: 'GET',
url: '/river-and-sea-levels/chester-cheshire-west-and-chester'
}

const response = await server.inject(options)
Code.expect(response.statusCode).to.equal(200)
Code.expect(response.payload).to.match(/Alyn at\s*Pontblyddyn\s*<span class="defra-flood-levels-table-subtitle"><span>\(Natural Resources Wales\)<\/span>/)
Code.expect(response.payload).to.contain('<span class="defra-flood-levels-table-numeric">0.73m</span>')
Code.expect(response.payload).to.contain('<span class="defra-flood-levels-table-trend__icon defra-flood-levels-tables-trend__icon--steady">')
Code.expect(response.payload).to.contain('<span class="defra-flood-levels-table-state defra-flood-levels-table-state--grey">NORMAL</span>')
})
})

0 comments on commit 15a2a1a

Please sign in to comment.