Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDPS-711 add landings roll count page #124

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions integration_tests/e2e/establishmentRoll.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Page from '../pages/page'
import EstablishmentRollPage from '../pages/EstablishmentRoll'
import { Role } from '../../server/enums/role'
import { assignedRollCountWithSpursMock } from '../../server/mocks/rollCountMock'
import LandingRollPage from '../pages/LandingRoll'
import { locationMock } from '../../server/mocks/locationMock'

context('Establishment Roll Page', () => {
beforeEach(() => {
Expand Down Expand Up @@ -67,10 +69,10 @@ context('Establishment Roll Page', () => {
const page = Page.verifyOnPage(EstablishmentRollPage)

page.assignedRollCountRows().eq(0).find('td').eq(0).should('contain.text', 'A').should('be.visible')
page.assignedRollCountRows().eq(1).find('td').eq(0).should('contain.text', 'Spur A1').should('not.be.visible')
page.assignedRollCountRows().eq(2).find('td').eq(0).should('contain.text', 'Landing A1X').should('not.be.visible')
page.assignedRollCountRows().eq(1).find('td').eq(0).should('contain.text', 'Spur a1').should('not.be.visible')
page.assignedRollCountRows().eq(2).find('td').eq(0).should('contain.text', 'Landing a1x').should('not.be.visible')
page.assignedRollCountRows().eq(3).find('td').eq(0).should('contain.text', 'B').should('be.visible')
page.assignedRollCountRows().eq(4).find('td').eq(0).should('contain.text', 'LANDING BY').should('not.be.visible')
page.assignedRollCountRows().eq(4).find('td').eq(0).should('contain.text', 'Landing by').should('not.be.visible')

const wing1Reveal = page.assignedRollCountRows().eq(0).find('td').eq(0).find('a')
wing1Reveal.click()
Expand All @@ -88,5 +90,68 @@ context('Establishment Roll Page', () => {
wing2Reveal.click()
page.assignedRollCountRows().eq(4).find('td').eq(0).should('not.be.visible')
})

it('should show link to landing pages when wing has spur', () => {
cy.task('stubGetLocation', { locationId: 1, payload: { ...locationMock, description: 'WING 1' } })
cy.task('stubGetLocation', { locationId: 2, payload: { ...locationMock, description: 'Spur 1' } })
cy.task('stubGetLocation', { locationId: 3, payload: { ...locationMock, description: 'Landing 1' } })
cy.task('stubRollCount', {
payload: assignedRollCountWithSpursMock,
query: '?wingOnly=false&showCells=true&parentLocationId=3',
})

const page = Page.verifyOnPage(EstablishmentRollPage)

const wing1Reveal = page.assignedRollCountRows().eq(0).find('td').eq(0).find('a')
wing1Reveal.click()
page.assignedRollCountRows().eq(2).find('td').eq(0).find('a').click()

const landingPage = Page.verifyOnPageWithTitle(LandingRollPage, 'Wing 1 - Spur 1 - Landing 1')

landingPage.rollCountRows().should('have.length', 5)

landingPage.rollCountRows().eq(0).find('td').eq(0).should('contain.text', 'A')
landingPage.rollCountRows().eq(1).find('td').eq(0).should('contain.text', 'Spur a1')
landingPage.rollCountRows().eq(2).find('td').eq(0).should('contain.text', 'Landing a1x')
landingPage.rollCountRows().eq(3).find('td').eq(0).should('contain.text', 'B')
landingPage.rollCountRows().eq(4).find('td').eq(0).should('contain.text', 'Landing by')

landingPage.rollCountRows().first().find('td').eq(1).should('contain.text', '76')
landingPage.rollCountRows().first().find('td').eq(2).should('contain.text', '900')
landingPage.rollCountRows().first().find('td').eq(3).should('contain.text', '5')
landingPage.rollCountRows().first().find('td').eq(4).should('contain.text', '60')
landingPage.rollCountRows().first().find('td').eq(5).should('contain.text', '-16')
})

it('should show link to landing pages when wing does not have spur', () => {
cy.task('stubGetLocation', { locationId: 4, payload: { ...locationMock, description: 'WING 1' } })
cy.task('stubGetLocation', { locationId: 5, payload: { ...locationMock, description: 'Landing 1' } })
cy.task('stubRollCount', {
payload: assignedRollCountWithSpursMock,
query: '?wingOnly=false&showCells=true&parentLocationId=5',
})

const page = Page.verifyOnPage(EstablishmentRollPage)

const wing2Reveal = page.assignedRollCountRows().eq(3).find('td').eq(0).find('a')
wing2Reveal.click()
page.assignedRollCountRows().eq(4).find('td').eq(0).find('a').click()

const landingPage = Page.verifyOnPageWithTitle(LandingRollPage, 'Wing 1 - Landing 1')

landingPage.rollCountRows().should('have.length', 5)

landingPage.rollCountRows().eq(0).find('td').eq(0).should('contain.text', 'A')
landingPage.rollCountRows().eq(1).find('td').eq(0).should('contain.text', 'Spur a1')
landingPage.rollCountRows().eq(2).find('td').eq(0).should('contain.text', 'Landing a1x')
landingPage.rollCountRows().eq(3).find('td').eq(0).should('contain.text', 'B')
landingPage.rollCountRows().eq(4).find('td').eq(0).should('contain.text', 'Landing by')

landingPage.rollCountRows().first().find('td').eq(1).should('contain.text', '76')
landingPage.rollCountRows().first().find('td').eq(2).should('contain.text', '900')
landingPage.rollCountRows().first().find('td').eq(3).should('contain.text', '5')
landingPage.rollCountRows().first().find('td').eq(4).should('contain.text', '60')
landingPage.rollCountRows().first().find('td').eq(5).should('contain.text', '-16')
})
})
})
18 changes: 17 additions & 1 deletion integration_tests/mockApis/prison.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { stubFor } from './wiremock'
import { CaseLoad } from '../../server/data/interfaces/caseLoad'
import { Location } from '../../server/data/interfaces/location'
import { locationsMock } from '../../server/mocks/locationMock'
import { locationMock, locationsMock } from '../../server/mocks/locationMock'
import { assignedRollCountMock, unassignedRollCountMock } from '../../server/mocks/rollCountMock'
import { movementsMock } from '../../server/mocks/movementsMock'
import { mockStaffRoles } from '../../server/mocks/staffRolesMock'
Expand Down Expand Up @@ -119,6 +119,22 @@ export default {
})
},

stubGetLocation: ({ locationId = 123, payload = locationMock } = {}) => {
return stubFor({
request: {
method: 'GET',
url: `/prison/api/locations/${locationId}`,
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: payload,
},
})
},

getAttributesForLocation: (locationId = 1) => {
return stubFor({
request: {
Expand Down
9 changes: 9 additions & 0 deletions integration_tests/pages/LandingRoll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Page, { PageElement } from './page'

export default class LandingRollPage extends Page {
constructor(title: string) {
super(title)
}

rollCountRows = (): PageElement => cy.get('table.landing-roll__table tbody tr')
}
4 changes: 4 additions & 0 deletions integration_tests/pages/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export default abstract class Page {
return new constructor()
}

static verifyOnPageWithTitle<T>(constructor: new (title: string) => T, title: string): T {
return new constructor(title)
}

constructor(private readonly title: string) {
this.checkOnPage()
}
Expand Down
17 changes: 17 additions & 0 deletions server/controllers/establishmentRollController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ export default class EstablishmentRollController {
res.render('pages/establishmentRoll', { establishmentRollCounts, date: new Date() })
}
}

public getEstablishmentRollForLanding(): RequestHandler {
return async (req: Request, res: Response) => {
const { user } = res.locals
const { clientToken } = req.middleware
const { landingId, wingId, spurId } = req.params

const [landingRollCounts, wing, spur, landing] = await Promise.all([
this.establishmentRollService.getLandingRollCounts(clientToken, user.activeCaseLoadId, Number(landingId)),
this.establishmentRollService.getLocationInfo(clientToken, wingId),
spurId ? this.establishmentRollService.getLocationInfo(clientToken, spurId) : null,
this.establishmentRollService.getLocationInfo(clientToken, landingId),
])

res.render('pages/establishmentRollLanding', { landingRollCounts, wing, spur, landing })
}
}
}
6 changes: 5 additions & 1 deletion server/data/interfaces/prisonApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import { OffenderCell } from './offenderCell'
export interface PrisonApiClient {
getUserCaseLoads(): Promise<CaseLoad[]>
getUserLocations(): Promise<Location[]>
getRollCount(prisonId: string, options?: { unassigned?: boolean; wingOnly?: boolean }): Promise<BlockRollCount[]>
getRollCount(
prisonId: string,
options?: { unassigned?: boolean; wingOnly?: boolean; showCells?: boolean; parentLocationId?: number },
): Promise<BlockRollCount[]>
getEnrouteRollCount(prisonId: string): Promise<number>
getLocationsForPrison(prisonId: string): Promise<Location[]>
getLocation(locationId: string): Promise<Location>
getAttributesForLocation(locationId: number): Promise<OffenderCell>
getMovements(prisonId: string): Promise<Movements>
getStaffRoles(staffId: number, agencyId: string): Promise<StaffRole[]>
Expand Down
6 changes: 5 additions & 1 deletion server/data/prisonApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class PrisonApiRestClient implements PrisonApiClient {

getRollCount(
prisonId: string,
queryOptions: { unassigned?: boolean; wingOnly?: boolean } = {},
queryOptions: { unassigned?: boolean; wingOnly?: boolean; showCells?: boolean; parentLocationId?: number } = {},
): Promise<BlockRollCount[]> {
return this.get<BlockRollCount[]>({
path: `/api/movements/rollcount/${prisonId}`,
Expand All @@ -49,6 +49,10 @@ export default class PrisonApiRestClient implements PrisonApiClient {
return this.get<Location[]>({ path: `/api/agencies/${prisonId}/locations` })
}

getLocation(locationId: string): Promise<Location> {
return this.get<Location>({ path: `/api/locations/${locationId}` })
}

getAttributesForLocation(locationId: number): Promise<OffenderCell> {
return this.get<OffenderCell>({ path: `/api/cell/${locationId}/attributes` })
}
Expand Down
28 changes: 28 additions & 0 deletions server/routes/establishmentRollRouter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { RequestHandler, Router } from 'express'
import { Services } from '../services'
import asyncMiddleware from '../middleware/asyncMiddleware'
import getFrontendComponents from '../middleware/frontEndComponents'
import config from '../config'
import EstablishmentRollController from '../controllers/establishmentRollController'

export default function establishmentRollRouter(services: Services): Router {
const router = Router()
router.get('*', getFrontendComponents(services, config.apis.frontendComponents.latest))

const get = (path: string | string[], ...handlers: RequestHandler[]) =>
router.get(
path,
handlers.map(handler => asyncMiddleware(handler)),
)

const establishmentRollController = new EstablishmentRollController(services.establishmentRollService)

get('/', establishmentRollController.getEstablishmentRoll())

get(
['/wing/:wingId/landing/:landingId', '/wing/:wingId/spur/:spurId/landing/:landingId'],
establishmentRollController.getEstablishmentRollForLanding(),
)

return router
}
9 changes: 2 additions & 7 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import whatsNewRouter from './whatsNewRouter'
import ApiController from '../controllers/apiController'
import getFrontendComponents from '../middleware/frontEndComponents'
import managedPageRouter from './managedPageRouter'
import establishmentRollRouter from './establishmentRollRouter'
import config from '../config'
import EstablishmentRollController from '../controllers/establishmentRollController'

export default function routes(services: Services): Router {
const router = Router()
Expand All @@ -28,18 +28,13 @@ export default function routes(services: Services): Router {
services.todayCache,
services.contentfulService,
)
const establishmentRollController = new EstablishmentRollController(services.establishmentRollService)
const apiController = new ApiController(services.homepageService)

get('/', getFrontendComponents(services, config.apis.frontendComponents.latest), homepageController.displayHomepage())
post('/search', homepageController.search())
get(
'/establishment-roll',
getFrontendComponents(services, config.apis.frontendComponents.latest),
establishmentRollController.getEstablishmentRoll(),
)

router.use(managedPageRouter(services))
router.use('/establishment-roll', establishmentRollRouter(services))

get('/api/dps-services', async (req, res, next) => {
res.setHeader('Content-Type', 'application/json')
Expand Down
Loading