Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass user into bedTableRows() and actionCell()
Browse files Browse the repository at this point in the history
We're going to render different HREFs in the bed
"Manage" link depending on whether the logged in
user has the FUTURE_MANAGER role. As a preliminary
we pass in the "user" object without changing any
behaviour.
edavey committed Jul 4, 2024
1 parent 6c84164 commit 0ad1c86
Showing 3 changed files with 17 additions and 9 deletions.
17 changes: 12 additions & 5 deletions server/utils/bedUtils.test.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import {
bedOccupancyEntryLostBedUiFactory,
bedOccupancyEntryOverbookingUiFactory,
bedSummaryFactory,
userDetailsFactory,
} from '../testutils/factories'
import {
InvalidOverbookingDataException,
@@ -64,19 +65,25 @@ describe('bedUtils', () => {
})

describe('actionCell', () => {
it('returns a link to manage the room', () => {
expect(actionCell(bed, premisesId)).toEqual({
html: bedLink(bed, premisesId),
describe('when the user does NOT have the FUTURE_MANAGER role', () => {
const user = userDetailsFactory.build({ roles: ['manager'] })

it('returns a "V1" link to manage the room', () => {
expect(actionCell(bed, premisesId, user)).toEqual({
html: bedLink(bed, premisesId),
})
})
})
})

describe('roomsTableRows', () => {
const user = userDetailsFactory.build({ roles: ['manager'] })

it('returns the table rows given the rooms', () => {
const beds = [bed]

expect(bedTableRows(beds, premisesId)).toEqual([
[roomNameCell(bed), bedNameCell(bed), statusCell(bed), actionCell(bed, premisesId)],
expect(bedTableRows(beds, premisesId, user)).toEqual([
[roomNameCell(bed), bedNameCell(bed), statusCell(bed), actionCell(bed, premisesId, user)],
])
})
})
7 changes: 4 additions & 3 deletions server/utils/bedUtils.ts
Original file line number Diff line number Diff line change
@@ -6,15 +6,16 @@ import {
SummaryListItem,
SummaryListWithCard,
TableCell,
UserDetails,
} from '../@types/ui'
import paths from '../paths/manage'
import { DateFormats } from './dateUtils'
import { linkTo, sentenceCase } from './utils'

export class InvalidOverbookingDataException extends Error {}

export const bedTableRows = (beds: Array<BedSummary>, premisesId: string) => {
return beds.map(bed => [roomNameCell(bed), bedNameCell(bed), statusCell(bed), actionCell(bed, premisesId)])
export const bedTableRows = (beds: Array<BedSummary>, premisesId: string, user?: UserDetails) => {
return beds.map(bed => [roomNameCell(bed), bedNameCell(bed), statusCell(bed), actionCell(bed, premisesId, user)])
}

export const bedNameCell = (item: { name: string }): TableCell => ({ text: item.name })
@@ -23,7 +24,7 @@ export const roomNameCell = (item: { roomName: string }): TableCell => ({ text:

export const statusCell = (bed: BedSummary): TableCell => ({ text: sentenceCase(bed.status) })

export const actionCell = (bed: BedSummary, premisesId: string): TableCell => ({
export const actionCell = (bed: BedSummary, premisesId: string, _user?: UserDetails): TableCell => ({
html: bedLink(bed, premisesId),
})

2 changes: 1 addition & 1 deletion server/views/premises/beds/index.njk
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@
text: 'Action'
}
],
rows: BedUtils.bedTableRows(beds, premisesId)
rows: BedUtils.bedTableRows(beds, premisesId, user)
})
}}
</div>

0 comments on commit 0ad1c86

Please sign in to comment.