From 80fac67bccf50488b9d0dace1a5c6a08beed5767 Mon Sep 17 00:00:00 2001 From: Ashley Gyngell Date: Tue, 20 Aug 2024 15:36:00 +0100 Subject: [PATCH] chore: refactor feature flag as comma seperated list & update tests --- feature.env | 2 +- helm_deploy/use-of-force/templates/_envs.tpl | 4 +-- helm_deploy/values-dev.yaml | 2 +- helm_deploy/values-preprod.yaml | 2 +- helm_deploy/values-prod.yaml | 2 +- server/config.js | 2 +- server/services/locationService.test.ts | 29 +++++++------------- server/services/locationService.ts | 2 +- 8 files changed, 18 insertions(+), 27 deletions(-) diff --git a/feature.env b/feature.env index 6f8c97c2..a49f08ef 100644 --- a/feature.env +++ b/feature.env @@ -15,7 +15,7 @@ EXIT_LOCATION_URL=/ DPS_URL=/ COMPONENT_API_URL=http://localhost:9091/components ENVIRONMENT_NAME=DEV -FEATURE_FLAG_REMOVE_CELL_LOCATIONS=HMI +FEATURE_FLAG_REMOVE_CELL_LOCATION_AGENCIES = ['HMI'] REDIS_HOST=localhost REDIS_PORT=6379 diff --git a/helm_deploy/use-of-force/templates/_envs.tpl b/helm_deploy/use-of-force/templates/_envs.tpl index 181255c3..782133fe 100644 --- a/helm_deploy/use-of-force/templates/_envs.tpl +++ b/helm_deploy/use-of-force/templates/_envs.tpl @@ -130,8 +130,8 @@ env: - name: ENVIRONMENT_NAME value: {{ .Values.env.ENVIRONMENT_NAME | quote }} - - name: FEATURE_FLAG_REMOVE_CELL_LOCATIONS - value: {{ .Values.env.FEATURE_FLAG_REMOVE_CELL_LOCATIONS | quote }} + - name: FEATURE_FLAG_REMOVE_CELL_LOCATION_AGENCIES + value: {{ .Values.env.FEATURE_FLAG_REMOVE_CELL_LOCATION_AGENCIES | quote }} - name: REDIS_HOST valueFrom: diff --git a/helm_deploy/values-dev.yaml b/helm_deploy/values-dev.yaml index 5ebcbf38..b5d6e855 100644 --- a/helm_deploy/values-dev.yaml +++ b/helm_deploy/values-dev.yaml @@ -24,7 +24,7 @@ env: TOKENVERIFICATION_API_URL: https://token-verification-api-dev.prison.service.justice.gov.uk TOKENVERIFICATION_API_ENABLED: true FEATURE_FLAG_OUTAGE_BANNER_ENABLED: false - FEATURE_FLAG_REMOVE_CELL_LOCATION: 'HMI' + FEATURE_FLAG_REMOVE_CELL_LOCATION_AGENCIES: ['HMI'] DPS_URL: https://digital-dev.prison.service.justice.gov.uk/ COMPONENT_API_URL: "https://frontend-components-dev.hmpps.service.justice.gov.uk" ENVIRONMENT_NAME: 'DEV' diff --git a/helm_deploy/values-preprod.yaml b/helm_deploy/values-preprod.yaml index 4bbae1a7..fac6d6a8 100644 --- a/helm_deploy/values-preprod.yaml +++ b/helm_deploy/values-preprod.yaml @@ -24,7 +24,7 @@ env: TOKENVERIFICATION_API_URL: https://token-verification-api-preprod.prison.service.justice.gov.uk TOKENVERIFICATION_API_ENABLED: true FEATURE_FLAG_OUTAGE_BANNER_ENABLED: false - FEATURE_FLAG_REMOVE_CELL_LOCATIONS: 'HMI' + FEATURE_FLAG_REMOVE_CELL_LOCATION_AGENCIES: ['HMI'] DPS_URL: https://digital-preprod.prison.service.justice.gov.uk/ COMPONENT_API_URL: "https://frontend-components-preprod.hmpps.service.justice.gov.uk" ENVIRONMENT_NAME: 'PRE-PRODUCTION' diff --git a/helm_deploy/values-prod.yaml b/helm_deploy/values-prod.yaml index f44c18ee..e96c347a 100644 --- a/helm_deploy/values-prod.yaml +++ b/helm_deploy/values-prod.yaml @@ -24,7 +24,7 @@ env: TOKENVERIFICATION_API_URL: https://token-verification-api.prison.service.justice.gov.uk TOKENVERIFICATION_API_ENABLED: true FEATURE_FLAG_OUTAGE_BANNER_ENABLED: false - FEATURE_FLAG_REMOVE_CELL_LOCATIONS: 'HMI' + FEATURE_FLAG_REMOVE_CELL_LOCATION_AGENCIES: ['HMI'] DPS_URL: https://digital.prison.service.justice.gov.uk/ COMPONENT_API_URL: "https://frontend-components.hmpps.service.justice.gov.uk" ENVIRONMENT_NAME: '' diff --git a/server/config.js b/server/config.js index f0cb66fd..d9451c9f 100755 --- a/server/config.js +++ b/server/config.js @@ -137,5 +137,5 @@ module.exports = { }, featureFlagOutageBannerEnabled: get('FEATURE_FLAG_OUTAGE_BANNER_ENABLED', 'false', requiredInProduction) === 'true', environmentName: get('ENVIRONMENT_NAME', ''), - featureFlagRemoveCellLocations: get('FEATURE_FLAG_REMOVE_CELL_LOCATIONS', ''), + featureFlagRemoveCellLocationAgencies: get('FEATURE_FLAG_REMOVE_CELL_LOCATION_AGENCIES', []), } diff --git a/server/services/locationService.test.ts b/server/services/locationService.test.ts index 9c8614be..5c05a7a0 100644 --- a/server/services/locationService.test.ts +++ b/server/services/locationService.test.ts @@ -163,7 +163,7 @@ describe('locationService', () => { ]) }) - it('should sort retrieved locations with only 1 primary location at the begining', async () => { + it('should sort retrieved locations with only 1 primary location at the beginning', async () => { prisonClient.getLocations.mockResolvedValue([ { userDescription: 'place 2' }, { userDescription: 'place 3' }, @@ -183,7 +183,7 @@ describe('locationService', () => { ]) }) - it('should sort retrieved locations with zero primary locations at the begining', async () => { + it('should sort retrieved locations with zero primary locations at the beginning', async () => { prisonClient.getLocations.mockResolvedValue([ { userDescription: 'place 2' }, { userDescription: 'place 3' }, @@ -225,8 +225,8 @@ describe('locationService', () => { expect(prisonClientBuilder).toBeCalledWith(token) }) - it('should remove cell locations for prison in feature flag', async () => { - config.featureFlagRemoveCellLocations = 'HMI' + it('should remove cell location options for prisons that are in and out of the feature flag', async () => { + config.featureFlagRemoveCellLocationAgencies = ['HMI', 'MDI'] prisonClient.getLocations.mockResolvedValue([ { userDescription: 'Other cell' }, { userDescription: "Prisoner's cell" }, @@ -234,23 +234,14 @@ describe('locationService', () => { { userDescription: 'Test wing' }, ] as PrisonLocation[]) - const result = await locationService.getIncidentLocations(token, 'HMI') + const result1 = await locationService.getIncidentLocations(token, 'HMI') + expect(result1).toEqual([{ userDescription: 'Test wing' }]) - expect(result).toEqual([{ userDescription: 'Test wing' }]) - }) - - it('should not remove cell locations for prison not in feature flag', async () => { - config.featureFlagRemoveCellLocations = 'HMI' - prisonClient.getLocations.mockResolvedValue([ - { userDescription: 'Other cell' }, - { userDescription: "Prisoner's cell" }, - { userDescription: 'In cell' }, - { userDescription: 'Test wing' }, - ] as PrisonLocation[]) + const result2 = await locationService.getIncidentLocations(token, 'MDI') + expect(result2).toEqual([{ userDescription: 'Test wing' }]) - const result = await locationService.getIncidentLocations(token, 'MDI') - - expect(result).toEqual([ + const result3 = await locationService.getIncidentLocations(token, 'ZZZ') + expect(result3).toEqual([ { userDescription: "Prisoner's cell" }, { userDescription: 'Other cell' }, { userDescription: 'In cell' }, diff --git a/server/services/locationService.ts b/server/services/locationService.ts index fbe3205b..47776199 100644 --- a/server/services/locationService.ts +++ b/server/services/locationService.ts @@ -52,7 +52,7 @@ export default class LocationService { location.userDescription.toUpperCase() !== 'IN CELL' ) .sort((a, b) => a.userDescription.localeCompare(b.userDescription, 'en', { ignorePunctuation: true })) - if (config.featureFlagRemoveCellLocations === agencyId) { + if (config.featureFlagRemoveCellLocationAgencies.includes(agencyId)) { return [...remainingLocations] } return [