From 71292c4ed6662abc206c1e8c26c6ba08741a562d Mon Sep 17 00:00:00 2001 From: Eli Selkin Date: Thu, 25 Jan 2024 14:17:08 -0800 Subject: [PATCH] VAMC system/facilities selectors, connectors, and tests (#27557) * selectors, connectors, and tests * rename test --- .../source-files/vamc-system/connect/index.js | 10 ++++ .../vamc-system/connect/preProcess.js | 18 +++++++ .../vamc-system/selectors/index.js | 10 ++++ .../vamc-system/tests/preProcess.unit.spec.js | 40 ++++++++++++++ .../vamc-system/tests/utils.unit.spec.js | 52 +++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 src/platform/site-wide/drupal-static-data/source-files/vamc-system/connect/index.js create mode 100644 src/platform/site-wide/drupal-static-data/source-files/vamc-system/connect/preProcess.js create mode 100644 src/platform/site-wide/drupal-static-data/source-files/vamc-system/selectors/index.js create mode 100644 src/platform/site-wide/drupal-static-data/source-files/vamc-system/tests/preProcess.unit.spec.js create mode 100644 src/platform/site-wide/drupal-static-data/source-files/vamc-system/tests/utils.unit.spec.js diff --git a/src/platform/site-wide/drupal-static-data/source-files/vamc-system/connect/index.js b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/connect/index.js new file mode 100644 index 000000000000..0482ccc9f87a --- /dev/null +++ b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/connect/index.js @@ -0,0 +1,10 @@ +import { connectDrupalStaticDataFile } from '../../../connect'; +import { preProcessSystemData } from './preProcess'; + +export const connectDrupalStaticDataFileVamcSystem = dispatch => { + connectDrupalStaticDataFile(dispatch, { + fileName: 'vamc-system.json', + preProcess: preProcessSystemData, + statePropName: 'vamcSystemData', + }); +}; diff --git a/src/platform/site-wide/drupal-static-data/source-files/vamc-system/connect/preProcess.js b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/connect/preProcess.js new file mode 100644 index 000000000000..da9d13cbffc8 --- /dev/null +++ b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/connect/preProcess.js @@ -0,0 +1,18 @@ +/** + * Structure of vamcSystemData: + * + * { + * "data": { + * "systems": { + * "VAMC System name": { + * "vhaId": "Facility name", + * } + * } + * } + * } + * vhaId is used to lookup the facility in whatever other source it's needed (e.g. police data is id'ed by facility vhaId) + */ + +export const preProcessSystemData = vamcSystemData => { + return vamcSystemData; +}; diff --git a/src/platform/site-wide/drupal-static-data/source-files/vamc-system/selectors/index.js b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/selectors/index.js new file mode 100644 index 000000000000..ed45d900db84 --- /dev/null +++ b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/selectors/index.js @@ -0,0 +1,10 @@ +// breaks unit tests if we use the workspace import +// eslint-disable-next-line @department-of-veterans-affairs/use-workspace-imports +import { selectDrupalStaticData } from 'platform/site-wide/drupal-static-data/selectors'; + +export const selectVamcSystemData = state => + selectDrupalStaticData(state)?.vamcSystemData?.data.systems || {}; + +// Returns an array of [vhaId, facilityName] tuples +export const selectFacilitiesForSystem = (state, systemName) => + Object.entries(selectVamcSystemData(state)?.[systemName] || {}) || []; diff --git a/src/platform/site-wide/drupal-static-data/source-files/vamc-system/tests/preProcess.unit.spec.js b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/tests/preProcess.unit.spec.js new file mode 100644 index 000000000000..54bf4ae902d0 --- /dev/null +++ b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/tests/preProcess.unit.spec.js @@ -0,0 +1,40 @@ +/* eslint-disable camelcase */ +import { expect } from 'chai'; +import { preProcessSystemData } from '../connect/preProcess'; + +describe('does nothing, output format is same as source', () => { + const vamcSystemData = { + data: { + systems: { + 'VA Pittsburgh health care': { + vha_646GC: 'Beaver County VA Clinic', + vha_646GA: 'Belmont County VA Clinic', + vha_646GE: 'Fayette County VA Clinic', + vha_646A4: + 'H. John Heinz III Department of Veterans Affairs Medical Center', + vha_646GF: 'Monroeville VA Clinic', + vha_646: 'Pittsburgh VA Medical Center-University Drive', + vha_646GD: 'Washington County VA Clinic', + vha_646GB: 'Westmoreland County VA Clinic', + }, + 'VA Altoona health care': { + vha_503GB: 'DuBois VA Clinic', + vha_503GD: 'Huntingdon County VA Clinic', + vha_503GE: 'Indiana County VA Clinic', + vha_503: "James E. Van Zandt Veterans' Administration Medical Center", + vha_503GA: 'Johnstown VA Clinic', + vha_503GC: 'State College VA Clinic', + }, + }, + }, + }; + + it('returns empty objects when no data present', () => { + const emptyVamcSystemData = {}; + expect(preProcessSystemData(emptyVamcSystemData)).to.deep.equal({}); + }); + + it('does not change input', () => { + expect(preProcessSystemData(vamcSystemData)).to.deep.equal(vamcSystemData); + }); +}); diff --git a/src/platform/site-wide/drupal-static-data/source-files/vamc-system/tests/utils.unit.spec.js b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/tests/utils.unit.spec.js new file mode 100644 index 000000000000..e5bfb3bfbb86 --- /dev/null +++ b/src/platform/site-wide/drupal-static-data/source-files/vamc-system/tests/utils.unit.spec.js @@ -0,0 +1,52 @@ +/* eslint-disable camelcase */ +import { expect } from 'chai'; +import { selectFacilitiesForSystem, selectVamcSystemData } from '../selectors'; + +describe('getVamcSystemNameFromVhaId', () => { + const drupalStaticData = { + drupalStaticData: { + vamcSystemData: { + data: { + systems: { + 'VA Pittsburgh health care': { + vha_646GC: 'Beaver County VA Clinic', + vha_646GA: 'Belmont County VA Clinic', + vha_646GE: 'Fayette County VA Clinic', + vha_646A4: + 'H. John Heinz III Department of Veterans Affairs Medical Center', + vha_646GF: 'Monroeville VA Clinic', + vha_646: 'Pittsburgh VA Medical Center-University Drive', + vha_646GD: 'Washington County VA Clinic', + vha_646GB: 'Westmoreland County VA Clinic', + }, + 'VA Altoona health care': { + vha_503GB: 'DuBois VA Clinic', + vha_503GD: 'Huntingdon County VA Clinic', + vha_503GE: 'Indiana County VA Clinic', + vha_503: + "James E. Van Zandt Veterans' Administration Medical Center", + vha_503GA: 'Johnstown VA Clinic', + vha_503GC: 'State College VA Clinic', + }, + }, + }, + }, + }, + }; + + it('selects VAMC facility id name tuples', () => { + expect(selectVamcSystemData(drupalStaticData)).to.deep.equal( + drupalStaticData.drupalStaticData.vamcSystemData.data.systems, + ); + expect( + selectFacilitiesForSystem(drupalStaticData, 'VA Altoona health care'), + ).to.deep.equal([ + ['vha_503GB', 'DuBois VA Clinic'], + ['vha_503GD', 'Huntingdon County VA Clinic'], + ['vha_503GE', 'Indiana County VA Clinic'], + ['vha_503', "James E. Van Zandt Veterans' Administration Medical Center"], + ['vha_503GA', 'Johnstown VA Clinic'], + ['vha_503GC', 'State College VA Clinic'], + ]); + }); +});