diff --git a/server/models/views/lib/latest-levels.js b/server/models/views/lib/latest-levels.js index 930efd5ea..dfa441748 100644 --- a/server/models/views/lib/latest-levels.js +++ b/server/models/views/lib/latest-levels.js @@ -1,10 +1,12 @@ const { formatElapsedTime } = require('../../../util') const WARNING_THRESHOLD_TYPES = ['FW RES FW', 'FW ACT FW', 'FW ACTCON FW'] -const EXCLUDED_STATUSES = ['ukcmf', 'Closed'] function getThresholdsForTargetArea (thresholds) { - const filteredThresholds = thresholds.filter(threshold => !EXCLUDED_STATUSES.includes(threshold.status)) + const filteredThresholds = thresholds.filter(threshold => + threshold.status !== 'Closed' && !(threshold.iswales && threshold.latest_level === null) + ) + const warningThresholds = findPrioritizedThresholds(filteredThresholds, WARNING_THRESHOLD_TYPES) return warningThresholds.map(formatThresholdTimestamp) } diff --git a/test/models/lib/latest-levels.js b/test/models/lib/latest-levels.js index 3d5048dd0..2d23eaa4e 100644 --- a/test/models/lib/latest-levels.js +++ b/test/models/lib/latest-levels.js @@ -61,9 +61,9 @@ lab.experiment('getThresholdsForTargetArea', () => { expect(result[0].formatted_time).to.equal('More than 2 hours ago') }) - lab.test('should exclude thresholds with status ukcmf or closed', () => { + lab.test('should exclude thresholds with status Closed', () => { const thresholds = [ - { rloi_id: 1, threshold_type: 'FW RES FW', status: 'ukcmf', value_timestamp: '2024-08-12T11:45:00.000Z' }, + { rloi_id: 1, threshold_type: 'FW RES FW', status: 'Closed', value_timestamp: '2024-08-12T11:45:00.000Z' }, { rloi_id: 2, threshold_type: 'FW RES FW', status: 'Active', value_timestamp: '2024-08-12T10:45:00.000Z' } ] @@ -74,16 +74,16 @@ lab.experiment('getThresholdsForTargetArea', () => { expect(result[0].formatted_time).to.equal('More than 2 hours ago') }) - lab.test('should exclude thresholds with status Closed', () => { + lab.test('should exclude Welsh stations with no data', () => { const thresholds = [ - { rloi_id: 1, threshold_type: 'FW RES FW', status: 'ukcmf', value_timestamp: '2024-08-12T11:45:00.000Z' }, - { rloi_id: 2, threshold_type: 'FW RES FW', status: 'Active', value_timestamp: '2024-08-12T10:45:00.000Z' } + { rloi_id: 1, threshold_type: 'FW RES FW', status: 'Active', iswales: true, latest_level: null, value_timestamp: '2024-08-12T11:45:00.000Z' }, + { rloi_id: 2, threshold_type: 'FW RES FW', status: 'Active', iswales: false, latest_level: '0.5', value_timestamp: '2024-08-12T10:45:00.000Z' } ] const result = getThresholdsForTargetArea(thresholds) expect(result).to.have.length(1) - expect(result[0].status).to.equal('Active') + expect(result[0].rloi_id).to.equal(2) expect(result[0].formatted_time).to.equal('More than 2 hours ago') })