From e74ee38b2e2b6ed1b1917ea39f90750c4d1daa07 Mon Sep 17 00:00:00 2001 From: Aaron Briggs <abriggs@contractor.usgs.gov> Date: Fri, 13 Aug 2021 13:22:10 -0500 Subject: [PATCH] test changes --- .../components/hydrograph/index.js | 5 ++- .../components/hydrograph/selectors/layout.js | 1 - .../hydrograph/time-series-graph.js | 2 +- .../store/hydrograph-data.js | 2 ++ .../src/scripts/web-services/sensor-things.js | 12 ++++++- .../web-services/sensor-things.test.js | 31 +++++++++++++++++++ wdfn-server/config.py | 4 +-- 7 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 assets/src/scripts/web-services/sensor-things.test.js diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.js index 8c9ac6033..1d008a6f6 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.js @@ -10,7 +10,7 @@ import {drawInfoAlert} from 'd3render/alerts'; import {renderTimeSeriesUrlParams} from 'ml/url-params'; -import {retrieveHydrographData} from 'ml/store/hydrograph-data'; +import {retrieveHydrographData, retrieveHydrographThresholds} from 'ml/store/hydrograph-data'; import {retrieveHydrographParameters} from 'ml/store/hydrograph-parameters'; import {setSelectedParameterCode, setCompareDataVisibility, setSelectedTimeSpan, setSelectedIVMethodID @@ -103,8 +103,11 @@ export const attachToNode = function(store, // Fetch waterwatch flood levels const fetchFloodLevelsPromise = store.dispatch(floodDataActions.retrieveWaterwatchData(siteno)); + // const fetchThresholdPromise = store.dispatch(retrieveHydrographThresholds(`${agencyCd}-${siteno}`)); let fetchDataPromises = [fetchHydrographDataPromise]; + // fetchDataPromises.push(fetchThresholdPromise); + // If flood levels are to be shown then wait to render the hydrograph until those have been fetched. if (parameterCode === config.GAGE_HEIGHT_PARAMETER_CODE) { fetchDataPromises.push(fetchFloodLevelsPromise); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/layout.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/layout.js index 9bc8ddbee..6d0810bbb 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/layout.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/layout.js @@ -56,7 +56,6 @@ export const getLayout = memoize(kind => createSelector( const margin = isDesktop ? MARGIN : MARGIN_SMALL_DEVICE; const tickLengths = yTickDetails.tickValues.map(v => yTickDetails.tickFormat(v).length); const approxLabelLength = Math.max(...tickLengths) * 10; -console.log('in get layout') return { width: width, height: height, diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js index f14f7dc46..661a4bf4c 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js @@ -19,7 +19,7 @@ import {getFloodLevelData} from './selectors/flood-level-data'; import {getIVDataSegments, HASH_ID} from './selectors/iv-data'; import {getMainLayout} from './selectors/layout'; import {getMainXScale, getMainYScale} from './selectors/scales'; -import {getTitle, getDescription, isVisible, getSelectedMethodDescription} from './selectors/time-series-data'; +import {getTitle, getDescription, isVisible} from './selectors/time-series-data'; import {drawGroundwaterLevels} from './discrete-data'; import {drawFloodLevelLines} from './flood-level-lines'; diff --git a/assets/src/scripts/monitoring-location/store/hydrograph-data.js b/assets/src/scripts/monitoring-location/store/hydrograph-data.js index d399cbb9b..9ecb0343c 100644 --- a/assets/src/scripts/monitoring-location/store/hydrograph-data.js +++ b/assets/src/scripts/monitoring-location/store/hydrograph-data.js @@ -361,6 +361,7 @@ export const retrieveHydrographData = function(siteno, agencyCode, {parameterCod let fetchPromises = []; if (hasIVData) { + // instead of calling this here, it would be called in index fetchPromises.push(dispatch(retrieveHydrographThresholds(`${agencyCode}-${siteno}`))); fetchPromises.push(dispatch(retrieveIVData( siteno, 'primary', {parameterCode, period, startTime, endTime}))); @@ -415,6 +416,7 @@ export const hydrographDataReducer = function(hydrographData = {}, action) { } case 'ADD_THRESHOLDS': { return { + // add this to general state instead of hydrographData ...hydrographData, thresholds: action.thresholds }; diff --git a/assets/src/scripts/web-services/sensor-things.js b/assets/src/scripts/web-services/sensor-things.js index 3d626d2ad..dd8f3151f 100644 --- a/assets/src/scripts/web-services/sensor-things.js +++ b/assets/src/scripts/web-services/sensor-things.js @@ -1,11 +1,21 @@ import {get} from 'ui/ajax'; import config from 'ui/config'; +/** + * Formats a URL to connect with the Sensor Things API. + * @param {String} agencySiteNumberCode - combines the Agency Code with the Site Number for example USGS-01646500 + * @return {String} URL for Sensor Things API + */ export const getSensorThingsURL = function(agencySiteNumberCode) { return `${config.SENSOR_THINGS_ENDPOINT}?$filter=name%20eq%20%27${agencySiteNumberCode}%27&$expand=Datastreams($select=name,description,properties,@iot.id)`; }; -export const fetchDataFromSensorThings = function(agencySiteNumberCode) { +/** + * Does the work of contacting the Sensor Things API and returning data + * @param {String} agencySiteNumberCode - combines the Agency Code with the Site Number for example USGS-01646500 + * @return {Promise} resolves to an empty object or one containing threshold information (and other secondary information) + */ +export const fetchDataFromSensorThings = function(agencySiteNumberCode) { return get(getSensorThingsURL(agencySiteNumberCode)) .catch(error => { console.error('Sensor Things did not return expected data. Reason: ', error.message); diff --git a/assets/src/scripts/web-services/sensor-things.test.js b/assets/src/scripts/web-services/sensor-things.test.js new file mode 100644 index 000000000..bd82d7f8f --- /dev/null +++ b/assets/src/scripts/web-services/sensor-things.test.js @@ -0,0 +1,31 @@ +import mockConsole from 'jest-mock-console'; +import sinon from 'sinon'; + +import {MOCK_SENSOR_THINGS_DATA} from 'ui/mock-service-data'; + +import {getSensorThingsURL, fetchDataFromSensorThings} from './groundwater-levels'; + +describe('web-services/sensor-things', () => { + let fakeServer; + let restoreConsole; + + beforeEach(() => { + fakeServer = sinon.createFakeServer(); + restoreConsole = mockConsole(); + }); + + afterEach(() => { + fakeServer.restore(); + restoreConsole(); + }); + + describe('getSensorThingsURL', () => { + it('Expects url to contain combined agency and site number', () => { + const result = getSensorThingsURL({ + siteno: 'USGS-01646500' + }); + expect(result).toContain('sites=11112222'); + + }); + }); +}); \ No newline at end of file diff --git a/wdfn-server/config.py b/wdfn-server/config.py index 5d592d51b..bc5838f06 100644 --- a/wdfn-server/config.py +++ b/wdfn-server/config.py @@ -25,8 +25,8 @@ HISTORICAL_IV_DATA_ENDPOINT = 'https://nwis.waterservices.usgs.gov/nwis/iv' STATISTICS_ENDPOINT = 'https://waterservices.usgs.gov/nwis/stat' GROUNDWATER_LEVELS_ENDPOINT = 'https://waterservices.usgs.gov/nwis/gwlevels/' MONITORING_LOCATIONS_OBSERVATIONS_ENDPOINT = 'https://labs.waterdata.usgs.gov/api/observations/collections/' -# SENSOR_THINGS_ENDPOINT = 'https://labs.waterdata.usgs.gov/sta/v1.1/Things' -SENSOR_THINGS_ENDPOINT = 'https://iow-frost-read-prod-external.wma.chs.usgs.gov/FROST-Server/v1.1/Things' +SENSOR_THINGS_ENDPOINT = 'https://labs.waterdata.usgs.gov/sta/v1.1/Things' +# SENSOR_THINGS_ENDPOINT = 'https://iow-frost-read-prod-external.wma.chs.usgs.gov/FROST-Server/v1.1/Things' NWISWEB_ENDPOINTS = { -- GitLab