Skip to content

Commit

Permalink
VB-3725 Select visitors page: add prison-specific visitor config (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpmcgowan authored May 14, 2024
1 parent bb50298 commit 5ae37f5
Show file tree
Hide file tree
Showing 30 changed files with 649 additions and 130 deletions.
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default defineConfig({
configFile: 'reporter-config.json',
},
taskTimeout: 60000,
viewportHeight: 1400,
e2e: {
setupNodeEvents(on) {
on('task', {
Expand Down
7 changes: 6 additions & 1 deletion integration_tests/e2e/bookingJourney.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ context('Booking journey', () => {
cy.task('stubGetPrisoners', { prisoners: [TestData.prisonerInfoDto()] })
cy.signIn()

// Home page - prisoner shown
const homePage = Page.verifyOnPage(HomePage)
homePage.prisonerName().contains('John Smith')
homePage.startButton().contains('Start')

// Start booking journey
cy.task('stubGetPrison')
cy.task('stubGetVisitors', {})
homePage.startBooking()

// TODO add to this test as booking journey implemented
})
Expand Down
36 changes: 35 additions & 1 deletion integration_tests/mockApis/orchestration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SuperAgentRequest } from 'superagent'
import { stubFor } from './wiremock'
import TestData from '../../server/routes/testutils/testData'
import { BookerReference, PrisonerInfoDto } from '../../server/data/orchestrationApiTypes'
import { BookerReference, PrisonDto, PrisonerInfoDto, VisitorInfoDto } from '../../server/data/orchestrationApiTypes'

export default {
stubGetBookerReference: (bookerReference = TestData.bookerReference()): SuperAgentRequest =>
Expand Down Expand Up @@ -36,6 +36,40 @@ export default {
},
}),

stubGetVisitors: ({
bookerReference = TestData.bookerReference(),
prisonerNumber = TestData.prisonerInfoDto().prisonerNumber,
visitors = [TestData.visitorInfoDto()],
}: {
bookerReference: BookerReference
prisonerNumber: string
visitors: VisitorInfoDto[]
}): SuperAgentRequest =>
stubFor({
request: {
method: 'GET',
url: `/orchestration/public/booker/${bookerReference.value}/prisoners/${prisonerNumber}/visitors`,
},
response: {
status: 200,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: visitors,
},
}),

stubGetPrison: (prisonDto: PrisonDto = TestData.prisonDto()): SuperAgentRequest =>
stubFor({
request: {
method: 'GET',
url: `/orchestration/config/prisons/prison/${prisonDto.code}`,
},
response: {
status: 200,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: prisonDto,
},
}),

stubOrchestrationPing: (status = 200): SuperAgentRequest =>
stubFor({
request: {
Expand Down
4 changes: 3 additions & 1 deletion integration_tests/pages/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ export default class HomePage extends Page {

prisonerName = (): PageElement => cy.get('[data-test=prisoner-name]')

startButton = (): PageElement => cy.get('[data-test="start-booking"]')
startBooking = (): void => {
cy.get('[data-test="start-booking"]').click()
}
}
87 changes: 0 additions & 87 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
"@types/bunyan-format": "^0.2.9",
"@types/compression": "^1.7.5",
"@types/connect-flash": "0.0.40",
"@types/cookie-session": "^2.0.49",
"@types/csurf": "^1.11.5",
"@types/express-session": "^1.18.0",
"@types/http-errors": "^2.0.4",
Expand All @@ -141,7 +140,6 @@
"axe-core": "^4.9.0",
"cheerio": "^1.0.0-rc.12",
"concurrently": "^8.2.2",
"cookie-session": "^2.1.0",
"cypress": "^13.8.1",
"cypress-axe": "^1.5.0",
"cypress-multi-reporters": "^1.6.4",
Expand Down
13 changes: 12 additions & 1 deletion server/@types/bapv.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrisonerInfoDto, VisitorInfoDto } from '../data/orchestrationApiTypes'
import { FieldValidationError } from 'express-validator'
import { PrisonDto, PrisonerInfoDto, VisitorInfoDto } from '../data/orchestrationApiTypes'

export type Booker = {
reference: string
Expand All @@ -9,8 +10,18 @@ export type Booker = {
export type BookingJourneyData = {
// selected prisoner for this visit
prisoner: PrisonerInfoDto

// prison for this visit
prison?: PrisonDto

// all possible visitors for this visit
allVisitors?: VisitorInfoDto[]

// selected visitors for this visit
selectedVisitors?: VisitorInfoDto[]
}

export type FlashData = {
errors?: FieldValidationError[]
formValues?: Record<string, string | string[]>
}
2 changes: 2 additions & 0 deletions server/@types/express/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ValidationError } from 'express-validator'
import { Booker, BookingJourneyData } from '../bapv'

export default {}
Expand Down Expand Up @@ -25,6 +26,7 @@ export declare global {

interface Request {
id: string
flash(type: 'errors', message: ValidationError[]): number
logout(done: (err: unknown) => void): void
}

Expand Down
15 changes: 15 additions & 0 deletions server/data/orchestrationApiClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@ describe('orchestrationApiClient', () => {
expect(result).toStrictEqual(visitors)
})
})

describe('getPrison', () => {
it('should get a prison by prisonCode', async () => {
const prison = TestData.prisonDto()

fakeOrchestrationApi
.get(`/config/prisons/prison/${prison.code}`)
.matchHeader('authorization', `Bearer ${token}`)
.reply(200, prison)

const result = await orchestrationApiClient.getPrison(prison.code)

expect(result).toStrictEqual(prison)
})
})
})
9 changes: 8 additions & 1 deletion server/data/orchestrationApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import RestClient from './restClient'
import config, { ApiConfig } from '../config'
import { AuthDetailDto, BookerReference, PrisonerInfoDto, VisitorInfoDto } from './orchestrationApiTypes'
import { AuthDetailDto, BookerReference, PrisonDto, PrisonerInfoDto, VisitorInfoDto } from './orchestrationApiTypes'

export default class OrchestrationApiClient {
private restClient: RestClient
Expand All @@ -9,6 +9,8 @@ export default class OrchestrationApiClient {
this.restClient = new RestClient('orchestrationApiClient', config.apis.orchestration as ApiConfig, token)
}

// public-booker-controller

async getBookerReference(authDetailDto: AuthDetailDto): Promise<BookerReference> {
return this.restClient.put({
path: '/public/booker/register/auth',
Expand All @@ -23,4 +25,9 @@ export default class OrchestrationApiClient {
async getVisitors(bookerReference: string, prisonerNumber: string): Promise<VisitorInfoDto[]> {
return this.restClient.get({ path: `/public/booker/${bookerReference}/prisoners/${prisonerNumber}/visitors` })
}

// orchestration-prisons-config-controller
async getPrison(prisonCode: string): Promise<PrisonDto> {
return this.restClient.get({ path: `/config/prisons/prison/${prisonCode}` })
}
}
2 changes: 2 additions & 0 deletions server/data/orchestrationApiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { components } from '../@types/orchestration-api'
export type AuthDetailDto = components['schemas']['AuthDetailDto']
export type BookerReference = components['schemas']['BookerReference']

export type PrisonDto = components['schemas']['PrisonDto']

export type PrisonerInfoDto = components['schemas']['PrisonerInfoDto']

export type VisitorInfoDto = components['schemas']['VisitorInfoDto']
2 changes: 1 addition & 1 deletion server/routes/bookingJourney/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function routes(services: Services): Router {
router.post(path, ...validationChain, asyncMiddleware(handler))

const selectPrisonerController = new SelectPrisonerController()
const selectVisitorsController = new SelectVisitorsController(services.bookerService)
const selectVisitorsController = new SelectVisitorsController(services.bookerService, services.prisonService)
const dateAndTimeController = new DateAndTimeController(services.bookerService)

// TODO need session checks for each stage to validate what is in session - add middleware here to apply to all booking journey routes?
Expand Down
Loading

0 comments on commit 5ae37f5

Please sign in to comment.