Skip to content

Commit

Permalink
Merge pull request #2257 from ministryofjustice/feature/APS-1623__occ…
Browse files Browse the repository at this point in the history
…upancy_view_add_ap_manager_to_matching_details

Occupancy View - Add AP Manager to matching details
  • Loading branch information
gregkhawkins authored Dec 18, 2024
2 parents 8021870 + 3d970eb commit 62eda52
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
5 changes: 4 additions & 1 deletion integration_tests/pages/match/occupancyViewPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ export default class OccupancyViewPage extends Page {
startDate: string,
durationDays: number,
placementRequest: PlacementRequest,
managerDetails: string,
) {
cy.get('.govuk-details').within(() => {
this.shouldContainSummaryListItems(occupancyViewSummaryListForMatchingDetails(totalCapacity, placementRequest))
this.shouldContainSummaryListItems(
occupancyViewSummaryListForMatchingDetails(totalCapacity, placementRequest, managerDetails),
)
})
cy.get('.govuk-heading-l')
.contains(
Expand Down
24 changes: 19 additions & 5 deletions integration_tests/tests/match/match.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ context('Placement Requests', () => {
const startDate = '2024-07-23'
const endDate = '2024-08-07'
const totalCapacity = 10
const managerDetails = 'John Doe'

// Given I am signed in as a cru_member
signIn(['cru_member'], ['cas1_space_booking_create'])
Expand All @@ -162,7 +163,7 @@ context('Placement Requests', () => {
duration: durationDays,
})
const premiseCapacity = cas1PremiseCapacityFactory.build({
premise: { id: premises.id, bedCount: totalCapacity },
premise: { id: premises.id, bedCount: totalCapacity, managerDetails },
startDate,
endDate,
})
Expand All @@ -175,7 +176,13 @@ context('Placement Requests', () => {
const occupancyViewPage = OccupancyViewPage.visit(placementRequest, premises, apType)

// Then I should see the details of the case I am matching
occupancyViewPage.shouldShowMatchingDetails(totalCapacity, startDate, durationDays, placementRequest)
occupancyViewPage.shouldShowMatchingDetails(
totalCapacity,
startDate,
durationDays,
placementRequest,
managerDetails,
)
return { occupancyViewPage, placementRequest, premiseCapacity, premises }
}

Expand All @@ -185,6 +192,7 @@ context('Placement Requests', () => {
const startDate = '2024-07-23'
const endDate = '2024-08-07'
const totalCapacity = 10
const managerDetails = 'John Doe'

// Given I am signed in as a cru_member
signIn(['cru_member'], ['cas1_space_booking_create'])
Expand All @@ -198,7 +206,7 @@ context('Placement Requests', () => {
duration: durationDays,
})
const premiseCapacity = cas1PremiseCapacityFactory.build({
premise: { id: premises.id, bedCount: totalCapacity },
premise: { id: premises.id, bedCount: totalCapacity, managerDetails },
startDate,
endDate,
})
Expand All @@ -211,7 +219,13 @@ context('Placement Requests', () => {
const occupancyViewPage = OccupancyViewPage.visit(placementRequest, premises, apType)

// Then I should see the details of the case I am matching
occupancyViewPage.shouldShowMatchingDetails(totalCapacity, startDate, durationDays, placementRequest)
occupancyViewPage.shouldShowMatchingDetails(
totalCapacity,
startDate,
durationDays,
placementRequest,
managerDetails,
)

// And I should see the filter form with populated values
occupancyViewPage.shouldShowFilters(startDate, 'Up to 6 weeks', [])
Expand All @@ -236,7 +250,7 @@ context('Placement Requests', () => {
const newDuration = 'Up to 1 week'
const newCriteria = ['Wheelchair accessible', 'Step-free']
const newPremiseCapacity = cas1PremiseCapacityFactory.build({
premise: { id: premises.id, bedCount: totalCapacity },
premise: { id: premises.id, bedCount: totalCapacity, managerDetails },
startDate: newStartDate,
endDate: newEndDate,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('OccupancyViewController', () => {
matchingDetailsSummaryList: occupancyViewSummaryListForMatchingDetails(
premiseCapacity.premise.bedCount,
placementRequestDetail,
premiseCapacity.premise.managerDetails,
),
summary: occupancySummary(premiseCapacity.capacity),
calendar: occupancyCalendar(premiseCapacity.capacity),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ export default class {
const durationDays = filterDurationDays || placementRequest.duration
const dateFieldValues = filterError ? filterUserInput : DateFormats.isoDateToDateInputs(startDate, 'startDate')

const matchingDetailsSummaryList = occupancyViewSummaryListForMatchingDetails(premises.bedCount, placementRequest)
let summary: OccupancySummary
let calendar: Calendar

let managerDetails: string
if (!errors.startDate) {
const capacityDates = placementDates(startDate, durationDays)
const capacity = await this.premisesService.getCapacity(
Expand All @@ -115,6 +114,7 @@ export default class {

summary = occupancySummary(capacity.capacity, filterCriteria)
calendar = occupancyCalendar(capacity.capacity, filterCriteria)
managerDetails = capacity.premise.managerDetails
}

res.render('match/placementRequests/occupancyView/view', {
Expand All @@ -128,7 +128,11 @@ export default class {
durationOptions: durationSelectOptions(durationDays),
criteriaOptions: convertKeyValuePairToCheckBoxItems(occupancyCriteriaMap, filterCriteria),
criteria: filterCriteria,
matchingDetailsSummaryList,
matchingDetailsSummaryList: occupancyViewSummaryListForMatchingDetails(
premises.bedCount,
placementRequest,
managerDetails,
),
summary,
calendar,
errors,
Expand Down
3 changes: 2 additions & 1 deletion server/testutils/factories/cas1PremisesSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { apAreaFactory } from './referenceData'

export default Factory.define<Cas1PremisesSummary>(() => ({
id: faker.string.uuid(),
name: `${faker.word.adjective()} ${faker.word.adverb()} ${faker.word.noun()}`,
name: `${faker.person}`,
postcode: faker.location.zipCode(),
apCode: `${faker.string.alpha(2)}`,
bedCount: 50,
availableBeds: faker.number.int({ min: 0, max: 50 }),
outOfServiceBeds: faker.number.int({ min: 0, max: 50 }),
apArea: apAreaFactory.build(),
supportsSpaceBookings: true,
managerDetails: `${faker.person}`,
overbookingSummary: [],
}))
15 changes: 13 additions & 2 deletions server/utils/match/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { DateFormats } from '../dateUtils'
import {
InvalidSpaceSearchDataException,
addressRow,
apManagerDetailsRow,
apTypeLabelsForRadioInput,
apTypeRow,
arrivalDateRow,
Expand Down Expand Up @@ -395,20 +396,22 @@ describe('matchUtils', () => {
})
const dates = placementDates(placementRequest.expectedArrival, placementRequest.duration)
const totalCapacity = 120
const managerDetails = 'John Doe'

it('should call the correct row functions', () => {
expect(occupancyViewSummaryListForMatchingDetails(totalCapacity, placementRequest)).toEqual([
expect(occupancyViewSummaryListForMatchingDetails(totalCapacity, placementRequest, managerDetails)).toEqual([
arrivalDateRow(dates.startDate),
departureDateRow(dates.endDate),
placementLengthRow(dates.placementLength),
releaseTypeRow(placementRequest),
totalCapacityRow(totalCapacity),
apManagerDetailsRow(managerDetails),
spaceRequirementsRow(filterOutAPTypes(placementRequest.essentialCriteria)),
])
})

it('should generate the expected matching details', () => {
expect(occupancyViewSummaryListForMatchingDetails(totalCapacity, placementRequest)).toEqual([
expect(occupancyViewSummaryListForMatchingDetails(totalCapacity, placementRequest, managerDetails)).toEqual([
{
key: {
text: 'Expected arrival date',
Expand Down Expand Up @@ -449,6 +452,14 @@ describe('matchUtils', () => {
text: '120 spaces',
},
},
{
key: {
text: 'AP manager details',
},
value: {
text: 'John Doe',
},
},
{
key: {
text: 'Space requirements',
Expand Down
11 changes: 11 additions & 0 deletions server/utils/match/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const spaceBookingPersonNeedsSummaryCardRows = (
export const occupancyViewSummaryListForMatchingDetails = (
totalCapacity: number,
placementRequest: PlacementRequest,
managerDetails: string,
): Array<SummaryListItem> => {
const placementRequestDates = placementDates(placementRequest.expectedArrival, placementRequest.duration)
const essentialCharacteristics = filterOutAPTypes(placementRequest.essentialCriteria)
Expand All @@ -185,6 +186,7 @@ export const occupancyViewSummaryListForMatchingDetails = (
placementLengthRow(placementRequestDates.placementLength),
releaseTypeRow(placementRequest),
totalCapacityRow(totalCapacity),
apManagerDetailsRow(managerDetails),
spaceRequirementsRow(essentialCharacteristics),
]
}
Expand Down Expand Up @@ -334,6 +336,15 @@ export const totalCapacityRow = (totalCapacity: number) => ({
},
})

export const apManagerDetailsRow = (apManagerDetails: string) => ({
key: {
text: 'AP manager details',
},
value: {
text: apManagerDetails,
},
})

export const spaceRequirementsRow = (essentialCharacteristics: Array<SpaceCharacteristic>) => ({
key: {
text: 'Space requirements',
Expand Down

0 comments on commit 62eda52

Please sign in to comment.