Skip to content

Commit

Permalink
Fix cell and non-residential view
Browse files Browse the repository at this point in the history
  • Loading branch information
Thource committed Jun 17, 2024
1 parent 87baa1c commit 2870bf8
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 77 deletions.
2 changes: 2 additions & 0 deletions integration_tests/e2e/viewLocations/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ context('View Locations Index', () => {
cy.task('stubManageUsersMe')
cy.task('stubManageUsersMeCaseloads')
cy.task('stubLocationsConstantsAccommodationType')
cy.task('stubLocationsConstantsConvertedCellType')
cy.task('stubLocationsConstantsDeactivatedReason')
cy.task('stubLocationsConstantsLocationType')
cy.task('stubLocationsConstantsSpecialistCellType')
cy.task('stubLocationsConstantsUsedForType')
cy.task('stubLocationsLocationsResidentialSummary')
Expand Down
56 changes: 38 additions & 18 deletions integration_tests/e2e/viewLocations/show.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ context('View Locations Show', () => {
cy.task('stubManageUsersMe')
cy.task('stubManageUsersMeCaseloads')
cy.task('stubLocationsConstantsAccommodationType')
cy.task('stubLocationsConstantsConvertedCellType')
cy.task('stubLocationsConstantsDeactivatedReason')
cy.task('stubLocationsConstantsLocationType')
cy.task('stubLocationsConstantsSpecialistCellType')
cy.task('stubLocationsConstantsUsedForType')
})
Expand Down Expand Up @@ -181,11 +183,27 @@ context('View Locations Show', () => {
detailsRows += 1
}

viewLocationsShowPage
.locationDetailsRows()
.eq(detailsRows)
.find('.govuk-summary-list__key')
.contains('Accommodation type')
if (location.status !== 'NON_RESIDENTIAL') {
if (location.locationType === 'CELL') {
viewLocationsShowPage
.locationDetailsRows()
.eq(detailsRows)
.find('.govuk-summary-list__key')
.contains('Cell type')
} else {
viewLocationsShowPage
.locationDetailsRows()
.eq(detailsRows)
.find('.govuk-summary-list__key')
.contains('Accommodation type')
}
} else {
viewLocationsShowPage
.locationDetailsRows()
.eq(detailsRows)
.find('.govuk-summary-list__key')
.contains('Non-residential room')
}
viewLocationsShowPage
.locationDetailsRows()
.eq(detailsRows)
Expand All @@ -207,17 +225,19 @@ context('View Locations Show', () => {
detailsRows += 1
}

viewLocationsShowPage
.locationDetailsRows()
.eq(detailsRows)
.find('.govuk-summary-list__key')
.contains('Last updated')
viewLocationsShowPage
.locationDetailsRows()
.eq(detailsRows)
.find('.govuk-summary-list__value')
.contains('Today by john smith')
detailsRows += 1
if (!location.leafLevel) {
viewLocationsShowPage
.locationDetailsRows()
.eq(detailsRows)
.find('.govuk-summary-list__key')
.contains('Last updated')
viewLocationsShowPage
.locationDetailsRows()
.eq(detailsRows)
.find('.govuk-summary-list__value')
.contains('Today by john smith')
detailsRows += 1
}

viewLocationsShowPage.locationDetailsRows().should('have.length', detailsRows)

Expand Down Expand Up @@ -407,10 +427,10 @@ context('View Locations Show', () => {
locationType: 'CELL',
permanentlyInactive: false,
accommodationTypes: ['TEST_TYPE'],
specialistCellTypes: [],
specialistCellTypes: ['TEST_TYPE'],
usedFor: [],
status: 'ACTIVE',
convertedCellType: 'OFFICE',
convertedCellType: 'TEST_TYPE',
active: true,
deactivatedByParent: false,
deactivatedReason: 'TEST_TYPE',
Expand Down
96 changes: 96 additions & 0 deletions integration_tests/mockApis/locationsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ const stubLocationsConstantsAccommodationType = () =>
},
})

const stubLocationsConstantsConvertedCellType = () =>
stubFor({
request: {
method: 'GET',
urlPattern: '/locations-api/constants/converted-cell-type',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: {
deactivatedReasons: [{ key: 'TEST_TYPE', description: 'Test type' }],
},
},
})

const stubLocationsConstantsDeactivatedReason = () =>
stubFor({
request: {
Expand All @@ -36,6 +53,80 @@ const stubLocationsConstantsDeactivatedReason = () =>
},
})

const stubLocationsConstantsLocationType = () =>
stubFor({
request: {
method: 'GET',
urlPattern: '/locations-api/constants/location-type',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: {
locationTypes: [
{ key: 'WING', description: 'Wing' },
{ key: 'LANDING', description: 'Landing' },
{ key: 'SPUR', description: 'Spur' },
{ key: 'CELL', description: 'Cell' },
{ key: 'ROOM', description: 'Room' },
],
},
},
})

const stubLocationsConstantsNonResidentialUsageType = () =>
stubFor({
request: {
method: 'GET',
urlPattern: '/locations-api/constants/non-residential-usage-type',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: {
nonResidentialUsageTypes: [{ key: 'TEST_TYPE', description: 'Test type' }],
},
},
})

const stubLocationsConstantsResidentialAttributeType = () =>
stubFor({
request: {
method: 'GET',
urlPattern: '/locations-api/constants/residential-attribute-type',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: {
residentialAttributeTypes: [{ key: 'TEST_TYPE', description: 'Test type' }],
},
},
})

const stubLocationsConstantsResidentialHousingType = () =>
stubFor({
request: {
method: 'GET',
urlPattern: '/locations-api/constants/residential-housing-type',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: {
residentialHousingTypes: [{ key: 'TEST_TYPE', description: 'Test type' }],
},
},
})

const stubLocationsConstantsSpecialistCellType = () =>
stubFor({
request: {
Expand Down Expand Up @@ -144,7 +235,12 @@ const stubLocationsLocationsResidentialSummaryForLocation = ({

export default {
stubLocationsConstantsAccommodationType,
stubLocationsConstantsConvertedCellType,
stubLocationsConstantsDeactivatedReason,
stubLocationsConstantsLocationType,
stubLocationsConstantsNonResidentialUsageType,
stubLocationsConstantsResidentialAttributeType,
stubLocationsConstantsResidentialHousingType,
stubLocationsConstantsSpecialistCellType,
stubLocationsConstantsUsedForType,
stubLocationsLocationsResidentialSummary,
Expand Down
33 changes: 33 additions & 0 deletions server/data/locationsApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,44 @@ export default class LocationsApiClient extends BaseApiClient {
requestType: 'get',
options: { cacheDuration: 86_400 },
}),
getConvertedCellTypes: this.apiCall<{ convertedCellTypes: { key: string; description: string }[] }, null>({
path: '/constants/converted-cell-type',
requestType: 'get',
options: { cacheDuration: 86_400 },
}),
getDeactivatedReasons: this.apiCall<{ deactivatedReasons: { key: string; description: string }[] }, null>({
path: '/constants/deactivated-reason',
requestType: 'get',
options: { cacheDuration: 86_400 },
}),
getLocationTypes: this.apiCall<{ locationTypes: { key: string; description: string }[] }, null>({
path: '/constants/location-type',
requestType: 'get',
options: { cacheDuration: 86_400 },
}),
getNonResidentialUsageTypes: this.apiCall<
{ nonResidentialUsageTypes: { key: string; description: string }[] },
null
>({
path: '/constants/non-residential-usage-type',
requestType: 'get',
options: { cacheDuration: 86_400 },
}),
getResidentialAttributeTypes: this.apiCall<
{ residentialAttributeTypes: { key: string; description: string }[] },
null
>({
path: '/constants/residential-attribute-type',
requestType: 'get',
options: { cacheDuration: 86_400 },
}),
getResidentialHousingTypes: this.apiCall<{ residentialHousingTypes: { key: string; description: string }[] }, null>(
{
path: '/constants/residential-housing-type',
requestType: 'get',
options: { cacheDuration: 86_400 },
},
),
getSpecialistCellTypes: this.apiCall<{ specialistCellTypes: { key: string; description: string }[] }, null>({
path: '/constants/specialist-cell-type',
requestType: 'get',
Expand Down
101 changes: 71 additions & 30 deletions server/decorators/location.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,79 @@ import decorateLocation from './location'
import ManageUsersService from '../services/manageUsersService'
import LocationsService from '../services/locationsService'

const manageUsersService = {
getUser: (_token: string, username: string) => {
return { name: `Resolved ${username}` }
},
} as unknown as ManageUsersService

const locationsService = {
getAccommodationType: (_token: string, type: string) => `Resolved ${type}`,
getConvertedCellType: (_token: string, type: string) => `Resolved ${type}`,
getDeactivatedReason: (_token: string, type: string) => `Resolved ${type}`,
getLocationType: (_token: string, type: string) => `Resolved ${type}`,
getSpecialistCellType: (_token: string, type: string) => `Resolved ${type}`,
getUsedForType: (_token: string, type: string) => `Resolved ${type}`,
} as unknown as LocationsService

describe('decorateLocation', () => {
it('populates accommodationTypes', async () => {
const location = LocationFactory.build({
accommodationTypes: ['TYPE1', 'TYPE2'],
deactivatedBy: 'DEACTIVATE_USER',
deactivatedReason: 'DEACTIVATED',
lastModifiedBy: 'MODIFIED_USER',
specialistCellTypes: ['TYPE1', 'TYPE2'],
usedFor: ['TYPE1', 'TYPE2'],
})
const decoratedLocation = await decorateLocation({
location,
systemToken: 'token',
userToken: 'token',
manageUsersService: {
getUser: (_token: string, username: string) => {
return { name: `Resolved ${username}` }
},
} as unknown as ManageUsersService,
locationsService: {
getAccommodationType: (_token: string, type: string) => `Resolved ${type}`,
getDeactivatedReason: (_token: string, type: string) => `Resolved ${type}`,
getSpecialistCellType: (_token: string, type: string) => `Resolved ${type}`,
getUsedForType: (_token: string, type: string) => `Resolved ${type}`,
} as unknown as LocationsService,
describe('when limited = false', () => {
it('decorates all of the fields', async () => {
const location = LocationFactory.build({
accommodationTypes: ['TYPE1', 'TYPE2'],
deactivatedBy: 'DEACTIVATE_USER',
deactivatedReason: 'DEACTIVATED',
lastModifiedBy: 'MODIFIED_USER',
specialistCellTypes: ['TYPE1', 'TYPE2'],
usedFor: ['TYPE1', 'TYPE2'],
})
const decoratedLocation = await decorateLocation({
location,
systemToken: 'token',
userToken: 'token',
manageUsersService,
locationsService,
limited: false,
})

expect(decoratedLocation.accommodationTypes).toEqual(location.accommodationTypes.map(s => `Resolved ${s}`))
expect(decoratedLocation.convertedCellType).toEqual(`Resolved ${location.convertedCellType}`)
expect(decoratedLocation.deactivatedBy).toEqual(`Resolved ${location.deactivatedBy}`)
expect(decoratedLocation.deactivatedReason).toEqual(`Resolved ${location.deactivatedReason}`)
expect(decoratedLocation.lastModifiedBy).toEqual(`Resolved ${location.lastModifiedBy}`)
expect(decoratedLocation.locationType).toEqual(`Resolved ${location.locationType}`)
expect(decoratedLocation.specialistCellTypes).toEqual(location.specialistCellTypes.map(s => `Resolved ${s}`))
expect(decoratedLocation.usedFor).toEqual(location.usedFor.map(s => `Resolved ${s}`))
})
})

describe('when limited = true', () => {
it('only decorates the expected fields', async () => {
const location = LocationFactory.build({
accommodationTypes: ['TYPE1', 'TYPE2'],
deactivatedBy: 'DEACTIVATE_USER',
deactivatedReason: 'DEACTIVATED',
lastModifiedBy: 'MODIFIED_USER',
specialistCellTypes: ['TYPE1', 'TYPE2'],
usedFor: ['TYPE1', 'TYPE2'],
})
const decoratedLocation = await decorateLocation({
location,
systemToken: 'token',
userToken: 'token',
manageUsersService,
locationsService,
limited: true,
})

expect(decoratedLocation.accommodationTypes).toEqual(location.accommodationTypes.map(s => `Resolved ${s}`))
expect(decoratedLocation.deactivatedBy).toEqual(`Resolved ${location.deactivatedBy}`)
expect(decoratedLocation.deactivatedReason).toEqual(`Resolved ${location.deactivatedReason}`)
expect(decoratedLocation.lastModifiedBy).toEqual(`Resolved ${location.lastModifiedBy}`)
expect(decoratedLocation.usedFor).toEqual(location.usedFor.map(s => `Resolved ${s}`))
expect(decoratedLocation.specialistCellTypes).toEqual(location.specialistCellTypes.map(s => `Resolved ${s}`))
expect(decoratedLocation.accommodationTypes).toEqual(location.accommodationTypes.map(s => `Resolved ${s}`))
expect(decoratedLocation.convertedCellType).toEqual(location.convertedCellType)
expect(decoratedLocation.deactivatedBy).toEqual(location.deactivatedBy)
expect(decoratedLocation.deactivatedReason).toEqual(location.deactivatedReason)
expect(decoratedLocation.lastModifiedBy).toEqual(location.lastModifiedBy)
expect(decoratedLocation.locationType).toEqual(`Resolved ${location.locationType}`)
expect(decoratedLocation.specialistCellTypes).toEqual(location.specialistCellTypes.map(s => `Resolved ${s}`))
expect(decoratedLocation.usedFor).toEqual(location.usedFor.map(s => `Resolved ${s}`))
})
})
})
Loading

0 comments on commit 2870bf8

Please sign in to comment.