Skip to content

Commit

Permalink
chore: refactor feature flag as comma seperated list & update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleygyngell committed Aug 20, 2024
1 parent f09d677 commit 80fac67
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion feature.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions helm_deploy/use-of-force/templates/_envs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion helm_deploy/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion helm_deploy/values-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion helm_deploy/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
2 changes: 1 addition & 1 deletion server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', []),
}
29 changes: 10 additions & 19 deletions server/services/locationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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' },
Expand Down Expand Up @@ -225,32 +225,23 @@ 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" },
{ userDescription: 'In cell' },
{ 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' },
Expand Down
2 changes: 1 addition & 1 deletion server/services/locationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit 80fac67

Please sign in to comment.