diff --git a/cypress_shared/components/bedspaceSearchResult.ts b/cypress_shared/components/bedspaceSearchResult.ts index 4b3df2df6..1ab55bf91 100644 --- a/cypress_shared/components/bedspaceSearchResult.ts +++ b/cypress_shared/components/bedspaceSearchResult.ts @@ -62,16 +62,8 @@ export default class BedspaceSearchResult extends Component { cy.root().contains(`CRN: ${overlap.crn}`) cy.root().contains(overlap.days === 1 ? '1 day overlap' : `${overlap.days} days overlap`) cy.get('a') - .contains('View booking') - .should( - 'have.attr', - 'href', - paths.bookings.show({ - premisesId: this.result.premises.id, - roomId: overlap.roomId, - bookingId: overlap.bookingId, - }), - ) + .contains(`View referral for ${overlap.name}`) + .should('have.attr', 'href', paths.assessments.summary({ id: overlap.assessmentId })) }) }) }) @@ -79,6 +71,6 @@ export default class BedspaceSearchResult extends Component { clickOverlapLink(crn: string) { cy.get('summary').contains('Other people staying').click() - cy.get('ul[data-cy-overlaps] > li').find('dd.overlap-details__value').contains(crn).parents('li').find('a').click() + cy.get('ul[data-cy-overlaps]').find('dd.overlap-details__value').contains(crn).parents('li').find('a').click() } } diff --git a/integration_tests/tests/temporary-accommodation/manage/bedspaceSearch.cy.ts b/integration_tests/tests/temporary-accommodation/manage/bedspaceSearch.cy.ts index 949dc9ce5..0231f9505 100644 --- a/integration_tests/tests/temporary-accommodation/manage/bedspaceSearch.cy.ts +++ b/integration_tests/tests/temporary-accommodation/manage/bedspaceSearch.cy.ts @@ -1,14 +1,14 @@ import Page from '../../../../cypress_shared/pages/page' import DashboardPage from '../../../../cypress_shared/pages/temporary-accommodation/dashboardPage' +import AssessmentSummaryPage from '../../../../cypress_shared/pages/assess/summary' import BedspaceSearchPage from '../../../../cypress_shared/pages/temporary-accommodation/manage/bedspaceSearch' import BedspaceShowPage from '../../../../cypress_shared/pages/temporary-accommodation/manage/bedspaceShow' -import BookingShowPage from '../../../../cypress_shared/pages/temporary-accommodation/manage/bookingShow' import { setupTestUser } from '../../../../cypress_shared/utils/setupTestUser' import { + assessmentFactory, bedSearchParametersFactory, bedSearchResultFactory, bedSearchResultsFactory, - bookingFactory, overlapFactory, personFactory, placeContextFactory, @@ -148,7 +148,7 @@ context('Bedspace Search', () => { Page.verifyOnPage(BedspaceShowPage, premises, room) }) - it('allows me to view an overlapping booking', () => { + it('allows me to view an overlapping offenders referral', () => { // Given I am signed in cy.signIn() @@ -163,9 +163,7 @@ context('Bedspace Search', () => { const premises = premisesFactory.build() const room = roomFactory.build() - const booking = bookingFactory.build({ - person, - }) + const assessment = assessmentFactory.build({ status: 'closed' }) const results = bedSearchResultsFactory.build({ results: [ @@ -176,7 +174,7 @@ context('Bedspace Search', () => { crn: person.crn, personType: person.type, roomId: room.id, - bookingId: booking.id, + assessmentId: assessment.id, days: 5, sex: person.sex, }), @@ -188,7 +186,7 @@ context('Bedspace Search', () => { cy.task('stubBedSearch', results) cy.task('stubSinglePremises', premises) cy.task('stubSingleRoom', { premisesId: premises.id, room }) - cy.task('stubBooking', { premisesId: premises.id, booking }) + cy.task('stubFindAssessment', { ...assessment, status: 'closed' }) // And when I fill out the form const searchParameters = bedSearchParametersFactory.build() @@ -199,7 +197,7 @@ context('Bedspace Search', () => { const postSearchPage = Page.verifyOnPage(BedspaceSearchPage, results) postSearchPage.clickOverlapLink(room, person.crn) - Page.verifyOnPage(BookingShowPage, premises, room, booking) + Page.verifyOnPage(AssessmentSummaryPage, assessment) }) it('shows errors when the API returns an error', () => { diff --git a/server/@types/shared/models/TemporaryAccommodationBedSearchResult.ts b/server/@types/shared/models/TemporaryAccommodationBedSearchResult.ts index 5a751c28e..ed51336e1 100644 --- a/server/@types/shared/models/TemporaryAccommodationBedSearchResult.ts +++ b/server/@types/shared/models/TemporaryAccommodationBedSearchResult.ts @@ -5,6 +5,6 @@ import type { BedSearchResult } from './BedSearchResult'; import type { TemporaryAccommodationBedSearchResultOverlap } from './TemporaryAccommodationBedSearchResultOverlap'; export type TemporaryAccommodationBedSearchResult = (BedSearchResult & { - overlaps: Array; + overlaps: Array>; }); diff --git a/server/testutils/factories/overlap.ts b/server/testutils/factories/overlap.ts index 63ee7c4d4..f2f9d8b44 100644 --- a/server/testutils/factories/overlap.ts +++ b/server/testutils/factories/overlap.ts @@ -1,14 +1,15 @@ import { fakerEN_GB as faker } from '@faker-js/faker' import { Factory } from 'fishery' import { TemporaryAccommodationBedSearchResultOverlap as Overlap } from '../../@types/shared' +import assessmentFactory from './assessment' import { fullPersonFactory } from './person' -export default Factory.define(() => ({ +export default Factory.define>(() => ({ crn: fullPersonFactory.build().crn, name: fullPersonFactory.build().name, sex: fullPersonFactory.build().sex, roomId: faker.string.uuid(), personType: fullPersonFactory.build().type, - bookingId: faker.string.uuid(), + assessmentId: assessmentFactory.build().id, days: faker.number.int({ min: 1, max: 100 }), })) diff --git a/server/utils/bedspaceSearchResultUtils.test.ts b/server/utils/bedspaceSearchResultUtils.test.ts index b16a60472..40e6d7436 100644 --- a/server/utils/bedspaceSearchResultUtils.test.ts +++ b/server/utils/bedspaceSearchResultUtils.test.ts @@ -1,7 +1,7 @@ import { FullPerson, RestrictedPerson, TemporaryAccommodationBedSearchResultOverlap } from '@approved-premises/api' import { + assessmentFactory, bedSearchResultFactory, - bookingFactory, characteristicFactory, premisesFactory, restrictedPersonFactory, @@ -66,7 +66,8 @@ describe('BedspaceSearchResultUtils', () => { describe('bedspaceOverlapResult', () => { let overLapDays: TemporaryAccommodationBedSearchResultOverlap['days'] - let overlapResult: Omit + let overlapResult: Omit + let overLapAssessmentId: TemporaryAccommodationBedSearchResultOverlap['assessmentId'] let person: FullPerson | RestrictedPerson const createOverLapResult = () => { @@ -75,7 +76,7 @@ describe('BedspaceSearchResultUtils', () => { days: overLapDays, personType: person.type, roomId: roomFactory.build().id, - bookingId: bookingFactory.build().id, + assessmentId: overLapAssessmentId, name: person.type === 'FullPerson' ? (person as FullPerson).name : 'Limited access offender', sex: person.type === 'FullPerson' ? (person as FullPerson).sex : undefined, } @@ -83,6 +84,7 @@ describe('BedspaceSearchResultUtils', () => { beforeEach(() => { overLapDays = 8 + overLapAssessmentId = assessmentFactory.build().id person = fullPersonFactory.build() overlapResult = createOverLapResult() }) @@ -93,9 +95,9 @@ describe('BedspaceSearchResultUtils', () => { overlapDays: '8 days overlap', personType: 'FullPerson', roomId: overlapResult.roomId, - bookingId: overlapResult.bookingId, + assessmentId: overlapResult.assessmentId, displayName: overlapResult.name, - sex: 'Male', + referralNameOrCrn: overlapResult.name, sex: overlapResult.sex, }) }) @@ -103,6 +105,7 @@ describe('BedspaceSearchResultUtils', () => { describe('when overlap by 1 day', () => { beforeEach(() => { overLapDays = 1 + overLapAssessmentId = assessmentFactory.build().id overlapResult = createOverLapResult() }) @@ -115,6 +118,7 @@ describe('BedspaceSearchResultUtils', () => { beforeEach(() => { overLapDays = 8 person = restrictedPersonFactory.build() + overLapAssessmentId = assessmentFactory.build().id overlapResult = createOverLapResult() }) @@ -124,10 +128,23 @@ describe('BedspaceSearchResultUtils', () => { overlapDays: '8 days overlap', personType: 'RestrictedPerson', roomId: overlapResult.roomId, - bookingId: overlapResult.bookingId, + referralNameOrCrn: overlapResult.crn, + assessmentId: overlapResult.assessmentId, displayName: 'Limited access offender', }) }) }) + + describe('when no assessment is assigned', () => { + beforeEach(() => { + overLapDays = 1 + overLapAssessmentId = undefined + overlapResult = createOverLapResult() + }) + + it('returns undefined for assessment ID', () => { + expect(bedspaceOverlapResult(overlapResult).assessmentId).toBeUndefined() + }) + }) }) }) diff --git a/server/utils/bedspaceSearchResultUtils.ts b/server/utils/bedspaceSearchResultUtils.ts index d87203892..9e67a7173 100644 --- a/server/utils/bedspaceSearchResultUtils.ts +++ b/server/utils/bedspaceSearchResultUtils.ts @@ -12,22 +12,22 @@ export function bedspaceKeyCharacteristics(result: BedSearchResult): Array characteristic.name) } -export function bedspaceOverlapResult( - overlapResult: Omit, -) { - const { crn, days, roomId, bookingId, personType } = overlapResult +export function bedspaceOverlapResult(overlapResult: Omit) { + const { crn, days, roomId, personType, assessmentId } = overlapResult const overlapDays = `${days} ${days === 1 ? 'day' : 'days'} overlap` const displayName = personType === 'FullPerson' ? overlapResult.name : 'Limited access offender' + const referralNameOrCrn = personType === 'FullPerson' ? overlapResult.name : overlapResult.crn const sex = personType === 'FullPerson' ? overlapResult.sex : undefined return { crn, overlapDays, roomId, - bookingId, personType, displayName, + referralNameOrCrn, sex, + assessmentId, } } diff --git a/server/views/components/overlap-details/macro.njk b/server/views/components/overlap-details/macro.njk index 843883ae5..34187499c 100644 --- a/server/views/components/overlap-details/macro.njk +++ b/server/views/components/overlap-details/macro.njk @@ -25,8 +25,14 @@
{{ params.overlap.overlapDays }}
- - View booking - + + {% if params.overlap.assessmentId %} + + View referral for {{ params.overlap.referralNameOrCrn }} + + {% else %} +

No referral found.

+ {% endif %} + {% endmacro %}