diff --git a/server/models/views/river-and-sea-levels.js b/server/models/views/river-and-sea-levels.js index 6579a4437..5636f5ad4 100644 --- a/server/models/views/river-and-sea-levels.js +++ b/server/models/views/river-and-sea-levels.js @@ -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) { diff --git a/test/data/chesterGetJson.json b/test/data/chesterGetJson.json new file mode 100644 index 000000000..e40899c72 --- /dev/null +++ b/test/data/chesterGetJson.json @@ -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" + } + \ No newline at end of file diff --git a/test/models/river-and-sea-levels.js b/test/models/river-and-sea-levels.js index 99cfd8caf..79e08c3b6 100644 --- a/test/models/river-and-sea-levels.js +++ b/test/models/river-and-sea-levels.js @@ -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', () => { @@ -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) + }) + }) }) diff --git a/test/routes/river-and-sea-levels.js b/test/routes/river-and-sea-levels.js index 56a866b44..1baa1d506 100644 --- a/test/routes/river-and-sea-levels.js +++ b/test/routes/river-and-sea-levels.js @@ -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*\(Natural Resources Wales\)<\/span>/) + Code.expect(response.payload).to.contain('0.73m') + Code.expect(response.payload).to.contain('') + Code.expect(response.payload).to.contain('NORMAL') + }) })