diff --git a/test/data/chesterGetJson.json b/test/data/chesterGetJson.json new file mode 100644 index 000000000..0f85eb51f --- /dev/null +++ b/test/data/chesterGetJson.json @@ -0,0 +1,58 @@ +{ + "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.36754, + -2.639558, + 53.42084, + -2.5353 + ], + "name": "Warrington, Warrington", + "point": { + "type": "Point", + "coordinates": [ + 53.39387, + -2.58935 + ] + }, + "address": { + "adminDistrict": "England", + "adminDistrict2": "Warrington", + "countryRegion": "United Kingdom", + "formattedAddress": "Warrington, Warrington", + "locality": "Warrington", + "countryRegionIso2": "GB" + }, + "confidence": "Medium", + "entityType": "PopulatedPlace", + "geocodePoints": [ + { + "type": "Point", + "coordinates": [ + 53.39387, + -2.58935 + ], + "calculationMethod": "Rooftop", + "usageTypes": [ + "Display" + ] + } + ], + "matchCodes": [ + "Good" + ] + } + ] + } + ], + "statusCode": 200, + "tatusDescription": "OK", + "traceId": "trace-id" + } \ No newline at end of file diff --git a/test/routes/river-and-sea-levels.js b/test/routes/river-and-sea-levels.js index 4fee88f1d..e77bdaa18 100644 --- a/test/routes/river-and-sea-levels.js +++ b/test/routes/river-and-sea-levels.js @@ -173,13 +173,188 @@ lab.experiment('Test - /river-and-sea-levels', () => { Code.expect(response.statusCode).to.equal(301) Code.expect(response.headers.location).to.equal('/river-and-sea-levels/warrington') }) + lab.test('GET /river-and-sea-levels should display height, trend, and state data for Natural Resources Wales stations', async () => { + const floodService = require('../../server/services/flood') - lab.test('GET /river-and-sea-levels/{location} with location', async () => { - stubs.getJson.callsFake(() => data.warringtonGetJson) - stubs.getIsEngland.callsFake(() => ({ is_england: true })) - stubs.getRiversByName.callsFake(() => []) - stubs.getStationsWithin.callsFake(() => []) + const fakeIsEngland = () => { + return { is_england: true } + } + + const fakeStationsData = () => [ + { + 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' + } + ] + + sandbox.stub(floodService, 'getIsEngland').callsFake(fakeIsEngland) + sandbox.stub(floodService, 'getStationsWithin').callsFake(fakeStationsData) + + const fakeGetJson = () => data.chesterGetJson + + const util = require('../../server/util') + sandbox.stub(util, 'getJson').callsFake(fakeGetJson) + + const riversPlugin = { + plugin: { + name: 'rivers', + register: (server, options) => { + server.route(require('../../server/routes/river-and-sea-levels')) + } + } + } + + await server.register(require('../../server/plugins/views')) + await server.register(require('../../server/plugins/session')) + await server.register(require('../../server/plugins/logging')) + await server.register(riversPlugin) + // Add Cache methods to server + const registerServerMethods = require('../../server/services/server-methods') + registerServerMethods(server) + + await server.initialize() + const options = { + method: 'GET', + url: '/river-and-sea-levels?q=Chester' + } + + const response = await server.inject(options) + + const root = parse(response.payload) + + checkTitleAndDescription( + root, + 'Chester - Find river, sea, groundwater and rainfall levels - GOV.UK', + 'Find river, sea, groundwater and rainfall levels in Chester. Check the last updated height, trend and state recorded by the measuring station.' + ) + + 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') + }) + lab.test('GET /river-and-sea-levels stations returned but location in Wales should not show stations', async () => { + const floodService = require('../../server/services/flood') + + const fakeIsEngland = () => { + return { is_england: false } + } + + const fakeStationsData = () => [ + { + river_id: 'lledan-brook', + river_name: 'Lledan Brook', + navigable: true, + view_rank: 3, + rank: 1, + rloi_id: 2089, + up: null, + down: null, + telemetry_id: '2638', + region: 'Wales', + catchment: 'Severn Uplands', + wiski_river_name: 'Lledan Brook', + agency_name: 'Welshpool', + external_name: 'Welshpool', + station_type: 'S', + status: 'Active', + qualifier: 'u', + iswales: true, + value: '0.297', + value_timestamp: '2020-03-04T09:00:00.000Z', + value_erred: false, + percentile_5: '0.36', + percentile_95: '0.065', + centroid: '0101000020E610000011F39E34DD3E09C0EDCA71828A544A40', + lon: -3.15569535360408, + lat: 52.6604769759777 + }, + { + river_id: 'river-severn', + river_name: 'River Severn', + navigable: true, + view_rank: 3, + rank: 7, + rloi_id: 2068, + up: 2072, + down: 2061, + telemetry_id: '2176', + region: 'Wales', + catchment: 'Severn Uplands', + wiski_river_name: 'River Severn', + agency_name: 'Buttington', + external_name: 'Buttington', + station_type: 'S', + status: 'Active', + qualifier: 'u', + iswales: true, + value: '3.192', + value_timestamp: '2020-03-04T09:00:00.000Z', + value_erred: false, + percentile_5: '3.509', + percentile_95: '0.756', + centroid: '0101000020E6100000188D8E3E20ED08C0AB99B41013564A40', + lon: -3.11578415749103, + lat: 52.6724568254316 + } + ] + + const fakeRiversData = () => [] + + sandbox.stub(floodService, 'getRiversByName').callsFake(fakeRiversData) + sandbox.stub(floodService, 'getIsEngland').callsFake(fakeIsEngland) + sandbox.stub(floodService, 'getStationsWithin').callsFake(fakeStationsData) + const fakeGetJson = () => data.welshLocationGetJson + + const util = require('../../server/util') + sandbox.stub(util, 'getJson').callsFake(fakeGetJson) + + const riversPlugin = { + plugin: { + name: 'rivers', + register: (server, options) => { + server.route(require('../../server/routes/river-and-sea-levels')) + } + } + } + + await server.register(require('../../server/plugins/views')) + await server.register(require('../../server/plugins/session')) + await server.register(require('../../server/plugins/logging')) + await server.register(riversPlugin) + // Add Cache methods to server + const registerServerMethods = require('../../server/services/server-methods') + registerServerMethods(server) + + await server.initialize() const options = { method: 'GET', url: '/river-and-sea-levels/warrington'