diff --git a/server/models/views/station.js b/server/models/views/station.js index 60096fe56..e74deb3c4 100644 --- a/server/models/views/station.js +++ b/server/models/views/station.js @@ -20,6 +20,7 @@ class ViewModel { this.station.riverNavigation = river this.id = station.id this.river = river + const isForecast = forecast ? forecast.forecastFlag.display_time_series : false this.station.trend = river.trend @@ -364,9 +365,8 @@ class ViewModel { // Forecast Data Calculations let forecastData - if (forecast) { - const { thresholds } = forecast - this.isFfoi = thresholds.length > 0 + if (isForecast) { + this.isFfoi = isForecast if (this.isFfoi) { forecastData = new Forecast(forecast, this.station.isCoastal, this.station.recentValue) this.isForecast = forecastData.hasForecastData diff --git a/server/routes/station-csv.js b/server/routes/station-csv.js index 689278f74..953c82daa 100644 --- a/server/routes/station-csv.js +++ b/server/routes/station-csv.js @@ -30,9 +30,9 @@ module.exports = { const stationName = station.external_name.replace(/[^a-zA-Z0-9]+/g, '-') - const [rawTelemetry, thresholds] = await Promise.all([ + const [rawTelemetry, forecastFlag] = await Promise.all([ floodService.getStationTelemetry(id, direction), - floodService.getStationForecastThresholds(id) + floodService.getForecastFlag(id, direction) ]) const telemetry = rawTelemetry.map(item => ({ @@ -42,7 +42,7 @@ module.exports = { })) // Forecast station - const includeForecast = !!thresholds.length + const includeForecast = forecastFlag.display_time_series const truncateDateHoursToAdd = 36 if (includeForecast && telemetry.length) { diff --git a/server/routes/station.js b/server/routes/station.js index 0d7b35a43..907d37d64 100644 --- a/server/routes/station.js +++ b/server/routes/station.js @@ -40,14 +40,14 @@ module.exports = { // batching all the service calls together, greatly improves page performance const [ telemetry, - thresholds, + forecastFlag, imtdThresholds, impacts, warningsAlerts, river ] = await Promise.all([ request.server.methods.flood.getStationTelemetry(id, direction), - request.server.methods.flood.getStationForecastThresholds(id), + request.server.methods.flood.getForecastFlag(id, direction), request.server.methods.flood.getStationImtdThresholds(id, direction), request.server.methods.flood.getImpactData(station.rloi_id), request.server.methods.flood.getWarningsAlertsWithinStationBuffer(station.rloi_id), @@ -60,11 +60,13 @@ module.exports = { return h.view('station', { model }) } + const hasForecast = forecastFlag.display_time_series + // Check if it's a forecast station - if (thresholds.length && station.status !== 'Suspended') { + if (hasForecast && station.status !== 'Suspended') { // Forecast station const values = await request.server.methods.flood.getStationForecastData(station.wiski_id) - const forecast = { thresholds, values } + const forecast = { forecastFlag, values } const model = new ViewModel({ station, telemetry, forecast, imtdThresholds, impacts, river, warningsAlerts }) return h.view('station', { model }) } else { diff --git a/server/services/flood.js b/server/services/flood.js index fe98ca6ff..6f6d92366 100644 --- a/server/services/flood.js +++ b/server/services/flood.js @@ -38,6 +38,10 @@ module.exports = { return util.getJson(`${serviceUrl}/stations`) }, + getForecastFlag (id, direction) { + return util.getJson(`${serviceUrl}/forecast-station/${id}/${direction}`) + }, + getStationsWithin (bbox) { const xyCoordsPath = bbox.join('/') return util.getJson(`${serviceUrl}/stations-within/${xyCoordsPath}`) @@ -72,10 +76,6 @@ module.exports = { return util.getJson(`${serviceUrl}/station/${id}/${direction}/telemetry`) }, - getStationForecastThresholds (id) { - return util.getJson(`${serviceUrl}/station/${id}/forecast/thresholds`) - }, - getStationImtdThresholds (id, direction) { return util.getJson(`${serviceUrl}/station/${id}/${direction}/imtd-thresholds`) }, diff --git a/server/services/server-methods.js b/server/services/server-methods.js index 0e4386c26..8d8effe2f 100644 --- a/server/services/server-methods.js +++ b/server/services/server-methods.js @@ -59,6 +59,14 @@ module.exports = server => { } }) + server.method('flood.getForecastFlag', floodServices.getForecastFlag, { + cache: { + cache: cacheType, + expiresIn: minutes(1), + generateTimeout: seconds(10) + } + }) + server.method('flood.getStations', floodServices.getStations, { cache: { cache: cacheType, @@ -124,14 +132,6 @@ module.exports = server => { } }) - server.method('flood.getStationForecastThresholds', floodServices.getStationForecastThresholds, { - cache: { - cache: cacheType, - expiresIn: minutes(1), - generateTimeout: seconds(10) - } - }) - server.method('flood.getStationImtdThresholds', floodServices.getStationImtdThresholds, { cache: { cache: cacheType, diff --git a/test/data/fakeNonForecastFlag.json b/test/data/fakeNonForecastFlag.json new file mode 100644 index 000000000..b7b3676e5 --- /dev/null +++ b/test/data/fakeNonForecastFlag.json @@ -0,0 +1,6 @@ +{ + "station_display_time_series_id": "94280", + "station_id": "1001", + "direction": "u", + "display_time_series": false + } diff --git a/test/data/forecastFlag.json b/test/data/forecastFlag.json new file mode 100644 index 000000000..29828215e --- /dev/null +++ b/test/data/forecastFlag.json @@ -0,0 +1,6 @@ +{ + "station_display_time_series_id": "94280", + "station_id": "8208", + "direction": "u", + "display_time_series": true + } diff --git a/test/plugins/rate-limit-disabled.js b/test/plugins/rate-limit-disabled.js index eb4176ad7..11159e00f 100644 --- a/test/plugins/rate-limit-disabled.js +++ b/test/plugins/rate-limit-disabled.js @@ -73,7 +73,7 @@ lab.experiment('rate-limit plugin disabled test', () => { percentile_5: '3.5', percentile_95: '0.15', comments: '', - status: 'Closed', + status: 'Active', status_reason: '', status_date: null, coordinates: '{"type":"Point","coordinates":[-2.68044442027032,53.7529105624953]}', @@ -83,19 +83,25 @@ lab.experiment('rate-limit plugin disabled test', () => { } const fakeTelemetryData = () => [] - + const fakeThresholdData = () => [] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] const fakeWarningsAlertsData = () => [] const fakeRiverStationData = () => [] - const fakeStationThresholdData = () => [0, 0] - sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) + const fakeForecastFlag = () => { + return { + station_display_time_series_id: '94280', + station_id: '8208', + direction: 'u', + display_time_series: false + } + } sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) + sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeThresholdData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) - sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeWarningsAlertsData) + sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverStationData) const stationPlugin = { diff --git a/test/plugins/rate-limit.js b/test/plugins/rate-limit.js index bfaa906e8..50f9af9e2 100644 --- a/test/plugins/rate-limit.js +++ b/test/plugins/rate-limit.js @@ -79,7 +79,7 @@ lab.experiment('rate-limit plugin test', () => { percentile_5: '3.5', percentile_95: '0.15', comments: '', - status: 'Closed', + status: 'Active', status_reason: '', status_date: null, coordinates: '{"type":"Point","coordinates":[-2.68044442027032,53.7529105624953]}', @@ -89,17 +89,26 @@ lab.experiment('rate-limit plugin test', () => { } const fakeTelemetryData = () => [] + const fakeThresholdData = () => [] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { + return { + station_display_time_series_id: '94280', + station_id: '8208', + direction: 'u', + display_time_series: false + } + } const fakeWarningsAlertsData = () => [] const fakeRiverStationData = () => [] - sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) + sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeThresholdData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeWarningsAlertsData) + sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverStationData) const stationPlugin = { diff --git a/test/routes/station-csv.js b/test/routes/station-csv.js index 68771f294..c3c63bbe9 100644 --- a/test/routes/station-csv.js +++ b/test/routes/station-csv.js @@ -65,24 +65,13 @@ lab.experiment('Routes test - station-csv', () => { } ] - const fakeThresholdsData = () => [ - { - ffoi_station_threshold_id: 133, - ffoi_station_id: 19, - fwis_code: '031WAF213', - fwis_type: 'FW ACTCON FAL', - value: 2, - fwa_name: 'River Leadon Catchment', - fwa_type: 'a', - fwa_severity: -1 - } - ] + const fakeForecastFlag = () => data.forecastFlag const fakeForecastData = () => data.csvForecastData sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationForecastData').callsFake(fakeForecastData) const response = await server.inject(options) @@ -153,11 +142,11 @@ lab.experiment('Routes test - station-csv', () => { } ] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) const response = await server.inject(options) Code.expect(response.statusCode).to.equal(200) @@ -226,11 +215,11 @@ lab.experiment('Routes test - station-csv', () => { } ] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) const response = await server.inject(options) Code.expect(response.statusCode).to.equal(200) @@ -299,11 +288,11 @@ lab.experiment('Routes test - station-csv', () => { } ] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) const response = await server.inject(options) Code.expect(response.headers['content-disposition']).to.equal('attachment; filename=Pilling-Broadfleet-height-data.csv') @@ -331,11 +320,11 @@ lab.experiment('Routes test - station-csv', () => { } ] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) const response = await server.inject(options) Code.expect(response.statusCode).to.equal(400) @@ -361,11 +350,11 @@ lab.experiment('Routes test - station-csv', () => { } ] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) const response = await server.inject(options) Code.expect(response.statusCode).to.equal(400) diff --git a/test/routes/station.js b/test/routes/station.js index e03be4e04..8fe3d1ec3 100644 --- a/test/routes/station.js +++ b/test/routes/station.js @@ -208,35 +208,7 @@ lab.experiment('Test - /station/{id}', () => { forecastactive: false } ] - const fakeForecastThresholds = () => [ - { - ffoi_station_threshold_id: 490, - ffoi_station_id: 80, - fwis_code: '062WAF46MidLee', - value: 0.6, - fwa_name: 'River Lee at Hertford', - fwa_type: 'a', - fwa_severity: -1 - }, - { - ffoi_station_threshold_id: 492, - ffoi_station_id: 80, - fwis_code: '062FWF46Hertford', - value: 0.85, - fwa_name: 'River Lee at Hertford and Ware', - fwa_type: 'w', - fwa_severity: -1 - }, - { - ffoi_station_threshold_id: 491, - ffoi_station_id: 80, - fwis_code: '062FWF46Lemsford', - value: 0.85, - fwa_name: 'River Lee from Lemsford to Hertford', - fwa_type: 'w', - fwa_severity: -1 - } - ] + const fakeForecastFlag = () => { return { } } const fakeStationForecastData = () => [] const fakeWarningsAlertsData = () => [] @@ -244,7 +216,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeForecastThresholds) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) @@ -373,7 +345,7 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => data.fakeNonForecastFlag const fakeTargetAreasData = () => [] const fakeStationThresholdData = () => [] @@ -381,7 +353,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeTargetAreasData) @@ -511,7 +483,7 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } const fakeWarningsAlertsData = () => [] const fakeStationThresholdData = () => [] @@ -519,7 +491,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeWarningsAlertsData) @@ -644,7 +616,7 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } const fakeWarningsAlertsData = () => [] const fakeStationThresholdData = () => [] @@ -652,7 +624,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeWarningsAlertsData) @@ -742,7 +714,7 @@ lab.experiment('Test - /station/{id}', () => { const fakeTelemetryData = () => [] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } const fakeWarningsAlertsData = () => [] const fakeRiverStationData = () => [] const fakeStationThresholdData = () => [] @@ -750,7 +722,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeWarningsAlertsData) sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverStationData) @@ -876,7 +848,7 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } const fakeWarningsAlertsData = () => [] const fakeStationThresholdData = () => [] @@ -884,7 +856,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeWarningsAlertsData) @@ -1012,7 +984,7 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } const fakeWarningsAlertsData = () => [] const fakeStationThresholdData = () => [] @@ -1020,7 +992,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeWarningsAlertsData) @@ -1229,35 +1201,7 @@ lab.experiment('Test - /station/{id}', () => { forecastactive: false } ] - const fakeForecastThresholds = () => [ - { - ffoi_station_threshold_id: 490, - ffoi_station_id: 80, - fwis_code: '062WAF46MidLee', - value: 0.6, - fwa_name: 'River Lee at Hertford', - fwa_type: 'a', - fwa_severity: -1 - }, - { - ffoi_station_threshold_id: 492, - ffoi_station_id: 80, - fwis_code: '062FWF46Hertford', - value: 0.85, - fwa_name: 'River Lee at Hertford and Ware', - fwa_type: 'w', - fwa_severity: -1 - }, - { - ffoi_station_threshold_id: 491, - ffoi_station_id: 80, - fwis_code: '062FWF46Lemsford', - value: 0.85, - fwa_name: 'River Lee from Lemsford to Hertford', - fwa_type: 'w', - fwa_severity: -1 - } - ] + const fakeForecastFlag = () => data.forecastFlag const fakeStationForecastData = () => data.fakeStationForecastData const fakeWarningsAlertsData = () => [] @@ -1265,7 +1209,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeForecastThresholds) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) @@ -1478,35 +1422,7 @@ lab.experiment('Test - /station/{id}', () => { forecastactive: false } ] - const fakeForecastThresholds = () => [ - { - ffoi_station_threshold_id: 490, - ffoi_station_id: 80, - fwis_code: '062WAF46MidLee', - value: 0.6, - fwa_name: 'River Lee at Hertford', - fwa_type: 'a', - fwa_severity: -1 - }, - { - ffoi_station_threshold_id: 492, - ffoi_station_id: 80, - fwis_code: '062FWF46Hertford', - value: 0.85, - fwa_name: 'River Lee at Hertford and Ware', - fwa_type: 'w', - fwa_severity: -1 - }, - { - ffoi_station_threshold_id: 491, - ffoi_station_id: 80, - fwis_code: '062FWF46Lemsford', - value: 0.85, - fwa_name: 'River Lee from Lemsford to Hertford', - fwa_type: 'w', - fwa_severity: -1 - } - ] + const fakeForecastFlag = () => data.forecastFlag const fakeStationForecastData = () => data.fakeStationForecastDataMax const fakeWarningsAlertsData = () => [] @@ -1517,7 +1433,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeForecastThresholds) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) @@ -1648,7 +1564,8 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } + const fakeTargetAreasData = () => [] const fakeStationThresholdData = () => [] @@ -1656,7 +1573,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeTargetAreasData) @@ -1938,7 +1855,8 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } + const fakeTargetAreasData = () => [] const fakeStationThresholdData = () => [] @@ -1946,7 +1864,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeTargetAreasData) @@ -2071,7 +1989,7 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } const fakeTargetAreasData = () => [] const fakeStationThresholdData = () => { return {} } @@ -2079,7 +1997,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeTargetAreasData) @@ -2202,7 +2120,7 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] + const fakeForecastFlag = () => { return { } } const fakeTargetAreasData = () => [] const fakeStationThresholdData = () => [] @@ -2210,7 +2128,7 @@ lab.experiment('Test - /station/{id}', () => { sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeTargetAreasData) @@ -2246,7 +2164,7 @@ lab.experiment('Test - /station/{id}', () => { Code.expect(response.payload).to.contain('Upstream') Code.expect(response.payload).to.contain('Download data CSV (12KB)') }) - lab.test('GET station/1034 - Coastal River title check ', async () => { + lab.test('GET station/1034 - Coastal River title check ', async () => { const floodService = require('../../server/services/flood') const fakeStationData = () => { @@ -2344,17 +2262,17 @@ lab.experiment('Test - /station/{id}', () => { ] const fakeImpactsData = () => [] - const fakeThresholdsData = () => [] - const fakeWarningsAlertsData = () => [] + const fakeForecastFlag = () => { return { } } + const fakeTargetAreasData = () => [] const fakeStationThresholdData = () => [] sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData) sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData) sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData) sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData) - sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData) + sandbox.stub(floodService, 'getForecastFlag').callsFake(fakeForecastFlag) sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData) - sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeWarningsAlertsData) + sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeTargetAreasData) const stationPlugin = { plugin: { diff --git a/test/services/flood.js b/test/services/flood.js index 6f772f14c..25028762a 100644 --- a/test/services/flood.js +++ b/test/services/flood.js @@ -234,19 +234,19 @@ lab.experiment('Flood service test', () => { Code.expect(result).to.equal('ok') }) - lab.test('Test getStationForecastThresholds endpoint', async () => { + lab.test('Test getForecastFlag endpoint', async () => { const util = require('../../server/util') sandbox .mock(util) .expects('getJson') - .withArgs('http://server2/station/7077/forecast/thresholds') + .withArgs('http://server2/forecast-station/2012/u') .once() .returns('ok') const floodService = require('../../server/services/flood') - const result = await floodService.getStationForecastThresholds(7077) + const result = await floodService.getForecastFlag(2012, 'u') Code.expect(result).to.equal('ok') })