Skip to content

Commit

Permalink
Add integration tests for booker management
Browse files Browse the repository at this point in the history
  • Loading branch information
tpmcgowan committed Aug 1, 2024
1 parent 0e8e0cd commit 01b2b1b
Show file tree
Hide file tree
Showing 13 changed files with 366 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { resetStubs } from './integration_tests/mockApis/wiremock'
import auth from './integration_tests/mockApis/auth'
import manageUsersApi from './integration_tests/mockApis/manageUsersApi'
import tokenVerification from './integration_tests/mockApis/tokenVerification'
import bookerRegistry from './integration_tests/mockApis/bookerRegistry'
import prisonerContactRegistry from './integration_tests/mockApis/prisonerContactRegistry'
import prisonRegister from './integration_tests/mockApis/prisonRegister'
import categoryGroups from './integration_tests/mockApis/visitScheduler/categoryGroups'
import incentiveGroups from './integration_tests/mockApis/visitScheduler/incentiveGroups'
Expand Down Expand Up @@ -32,6 +34,8 @@ export default defineConfig({
...manageUsersApi,
...tokenVerification,

...bookerRegistry,
...prisonerContactRegistry,
...prisonRegister,

// visit scheduler mock APIs
Expand Down
2 changes: 2 additions & 0 deletions feature.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ SYSTEM_CLIENT_ID=clientid
SYSTEM_CLIENT_SECRET=clientsecret
ENVIRONMENT_NAME=dev

BOOKER_REGISTRY_API_URL=http://localhost:9091/bookerRegistry
PRISONER_CONTACT_REGISTRY_API_URL=http://localhost:9091/prisonerContactRegistry
PRISON_REGISTER_API_URL=http://localhost:9091/prisonRegister
VISIT_SCHEDULER_API_URL=http://localhost:9091/visitScheduler
109 changes: 109 additions & 0 deletions integration_tests/e2e/bookers/bookerManagement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import TestData from '../../../server/routes/testutils/testData'
import IndexPage from '../../pages'
import AddNewBookerPage from '../../pages/bookers/addNewBooker'
import AddPrisonerPage from '../../pages/bookers/addPrisoner'
import AddVisitorPage from '../../pages/bookers/addVisitor'
import BookerDetailsPage from '../../pages/bookers/bookerDetails'
import SearchForBookerPage from '../../pages/bookers/searchForBooker'
import Page from '../../pages/page'

context('Booker management', () => {
const booker = TestData.bookerDto()
const prisoner = TestData.permittedPrisonerDto()
const contact = TestData.contact()
const bookerWithPrisoner = TestData.bookerDto({ permittedPrisoners: [TestData.permittedPrisonerDto()] })
const bookerWithPrisonerAndContacts = TestData.bookerDto({
permittedPrisoners: [
TestData.permittedPrisonerDto({
permittedVisitors: [{ visitorId: TestData.contact().personId, active: true }],
}),
],
})

beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubManageUser')
cy.signIn()
})

it('should look up a booker, add them and prisoner/visitor details', () => {
// Navigate to booker search page
const indexPage = Page.verifyOnPage(IndexPage)
indexPage.bookersCard().click()
const searchForBookerPage = Page.verifyOnPage(SearchForBookerPage)

// Search for booker
cy.task('stubGetBookerByEmailNotFound', booker)
searchForBookerPage.enterBookerEmail(booker.email)
searchForBookerPage.search()

// Booker not found - Add booker page - add booker
cy.task('stubCreateBooker', booker)
cy.task('stubGetBookerByEmail', booker)
cy.task('stubGetSocialContacts', { prisonerId: prisoner.prisonerId, contacts: [], approvedOnly: false })
const addNewBookerPage = Page.verifyOnPage(AddNewBookerPage)
addNewBookerPage.add()

// Booker details page
const bookerDetailsPage = Page.verifyOnPage(BookerDetailsPage)
bookerDetailsPage.bookerEmail().contains(booker.email)
bookerDetailsPage.bookerReference().contains(booker.reference)
bookerDetailsPage.prisonerNumber().contains('Not set')

// Add prisoner
bookerDetailsPage.addPrisoner()
const addPrisonerPage = Page.verifyOnPage(AddPrisonerPage)
addPrisonerPage.enterPrisonerNumber(prisoner.prisonerId)
cy.task('stubCreateBookerPrisoner', { booker, prisoner })
cy.task('stubGetBookerByEmail', bookerWithPrisoner)
cy.task('stubGetSocialContacts', { prisonerId: prisoner.prisonerId, contacts: [contact], approvedOnly: false })
addPrisonerPage.addPrisoner()

// Booker details - prisoner added
bookerDetailsPage.checkOnPage()
bookerDetailsPage.prisonerNumber().contains(prisoner.prisonerId)

// Add visitor
cy.task('stubGetSocialContacts', { prisonerId: prisoner.prisonerId, contacts: [contact], approvedOnly: true })
bookerDetailsPage.addVisitor()
const addVisitorPage = Page.verifyOnPage(AddVisitorPage)
addVisitorPage.selectVisitorById(contact.personId)
cy.task('stubCreateBookerPrisonerVisitor', { booker, prisoner, contact })
cy.task('stubGetBookerByEmail', bookerWithPrisonerAndContacts)
addVisitorPage.addVisitor()

// Booker details - visitor added
bookerDetailsPage.checkOnPage()
bookerDetailsPage.getVisitorName(1).contains(`${contact.firstName} ${contact.lastName}`)
})

it('should clear details for an existing booker', () => {
// Navigate to booker search page
const indexPage = Page.verifyOnPage(IndexPage)
indexPage.bookersCard().click()
const searchForBookerPage = Page.verifyOnPage(SearchForBookerPage)

// Search for booker
cy.task('stubGetBookerByEmail', bookerWithPrisonerAndContacts)
cy.task('stubGetSocialContacts', { prisonerId: prisoner.prisonerId, contacts: [contact], approvedOnly: false })
searchForBookerPage.enterBookerEmail(booker.email)
searchForBookerPage.search()

// Booker details page - prisoner and visitors present
const bookerDetailsPage = Page.verifyOnPage(BookerDetailsPage)
bookerDetailsPage.bookerEmail().contains(booker.email)
bookerDetailsPage.bookerReference().contains(booker.reference)
bookerDetailsPage.prisonerNumber().contains(prisoner.prisonerId)
bookerDetailsPage.getVisitorName(1).contains(`${contact.firstName} ${contact.lastName}`)

// Clear booker details
cy.task('stubClearBookerDetails', bookerWithPrisonerAndContacts)
cy.task('stubGetBookerByEmail', booker)
bookerDetailsPage.clearBookerDetails()

// Booker details page - no prisoner set
bookerDetailsPage.checkOnPage()
bookerDetailsPage.prisonerNumber().contains('Not set')
})
})
2 changes: 2 additions & 0 deletions integration_tests/e2e/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ context('Home page', () => {
const indexPage = Page.verifyOnPage(IndexPage)

indexPage.supportedPrisonsCard().contains('Supported prisons')

indexPage.bookersCard().contains('Bookers')
})
})
126 changes: 126 additions & 0 deletions integration_tests/mockApis/bookerRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { SuperAgentRequest } from 'superagent'
import { stubFor } from './wiremock'
import { BookerDto, PermittedPrisonerDto } from '../../server/data/bookerRegistryApiTypes'
import { ContactDto } from '../../server/data/prisonerContactRegistryApiTypes'

export default {
stubGetBookerByEmail: (booker: BookerDto): SuperAgentRequest => {
return stubFor({
request: {
method: 'GET',
url: `/bookerRegistry/public/booker/config/email/${booker.email}`,
},
response: {
status: 200,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: booker,
},
})
},

stubGetBookerByEmailNotFound: (booker: BookerDto): SuperAgentRequest => {
return stubFor({
request: {
method: 'GET',
url: `/bookerRegistry/public/booker/config/email/${booker.email}`,
},
response: {
status: 404,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
},
})
},

stubCreateBooker: (booker: BookerDto): SuperAgentRequest => {
return stubFor({
request: {
method: 'PUT',
url: '/bookerRegistry/public/booker/config',
bodyPatterns: [
{
equalToJson: {
email: booker.email,
},
},
],
},
response: {
status: 200,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: booker,
},
})
},

stubCreateBookerPrisoner: ({
booker,
prisoner,
}: {
booker: BookerDto
prisoner: PermittedPrisonerDto
}): SuperAgentRequest => {
return stubFor({
request: {
method: 'PUT',
url: `/bookerRegistry/public/booker/config/${booker.reference}/prisoner`,
bodyPatterns: [
{
equalToJson: {
prisonerId: prisoner.prisonerId,
active: true,
},
},
],
},
response: {
status: 200,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: prisoner,
},
})
},

stubCreateBookerPrisonerVisitor: ({
booker,
prisoner,
contact,
}: {
booker: BookerDto
prisoner: PermittedPrisonerDto
contact: ContactDto
}): SuperAgentRequest => {
return stubFor({
request: {
method: 'PUT',
url: `/bookerRegistry/public/booker/config/${booker.reference}/prisoner/${prisoner.prisonerId}/visitor`,
bodyPatterns: [
{
equalToJson: {
visitorId: contact.personId,
active: true,
},
},
],
},
response: {
status: 200,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: { visitorId: contact.personId, active: true },
},
})
},

stubClearBookerDetails: (booker: BookerDto): SuperAgentRequest => {
return stubFor({
request: {
method: 'DELETE',
url: `/bookerRegistry/public/booker/config/${booker.reference}`,
},
response: {
status: 200,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: { ...booker, permittedPrisoners: [] },
},
})
},
}
32 changes: 32 additions & 0 deletions integration_tests/mockApis/prisonerContactRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { SuperAgentRequest } from 'superagent'
import { stubFor } from './wiremock'
import { ContactDto } from '../../server/data/prisonerContactRegistryApiTypes'

export default {
stubGetSocialContacts: ({
prisonerId,
contacts,
approvedOnly,
}: {
prisonerId: string
contacts: ContactDto[]
approvedOnly: boolean
}): SuperAgentRequest => {
return stubFor({
request: {
method: 'GET',
urlPath: `/prisonerContactRegistry/prisoners/${prisonerId}/contacts/social`,
queryParameters: {
approvedVisitorsOnly: { equalTo: approvedOnly.toString() },
hasDateOfBirth: { equalTo: 'true' },
withAddress: { equalTo: 'false' },
},
},
response: {
status: 200,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: contacts,
},
})
},
}
11 changes: 11 additions & 0 deletions integration_tests/pages/bookers/addNewBooker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Page from '../page'

export default class AddNewBookerPage extends Page {
constructor() {
super('Add a new booker')
}

add = (): void => {
cy.get('[data-test="submit"]').click()
}
}
15 changes: 15 additions & 0 deletions integration_tests/pages/bookers/addPrisoner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Page from '../page'

export default class AddPrisonerPage extends Page {
constructor() {
super('Add a prisoner')
}

enterPrisonerNumber = (prisonerNumber: string): void => {
cy.get('#prisonerNumber').type(prisonerNumber)
}

addPrisoner = (): void => {
cy.get('[data-test="add-prisoner"]').click()
}
}
15 changes: 15 additions & 0 deletions integration_tests/pages/bookers/addVisitor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Page from '../page'

export default class AddVisitorPage extends Page {
constructor() {
super('Add a visitor')
}

selectVisitorById = (visitorId: number): void => {
cy.get(`#visitor-${visitorId.toString()}`).check()
}

addVisitor = (): void => {
cy.get('[data-test="add-visitor"]').click()
}
}
27 changes: 27 additions & 0 deletions integration_tests/pages/bookers/bookerDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Page, { PageElement } from '../page'

export default class BookerDetailsPage extends Page {
constructor() {
super('Booker details')
}

bookerEmail = (): PageElement => cy.get('[data-test="booker-email"]')

bookerReference = (): PageElement => cy.get('[data-test="booker-reference"]')

prisonerNumber = (): PageElement => cy.get('[data-test="prisoner-number"]')

addPrisoner = (): void => {
cy.get('[data-test="add-prisoner"]').click()
}

getVisitorName = (index: number): PageElement => cy.get(`[data-test="visitor-name-${index.toString()}"]`)

addVisitor = (): void => {
cy.get('[data-test="add-visitor"]').click()
}

clearBookerDetails = (): void => {
cy.get('[data-test="clear-booker-details"]').click()
}
}
15 changes: 15 additions & 0 deletions integration_tests/pages/bookers/searchForBooker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Page from '../page'

export default class SearchForBookerPage extends Page {
constructor() {
super('Search for a booker')
}

enterBookerEmail = (email: string): void => {
cy.get('#booker').type(email)
}

search = (): void => {
cy.get('[data-test="submit"]').click()
}
}
2 changes: 2 additions & 0 deletions integration_tests/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export default class IndexPage extends Page {
headerPhaseBanner = (): PageElement => cy.get('[data-qa=header-phase-banner]')

supportedPrisonsCard = (): PageElement => cy.get('[data-test="administer-prisons"]')

bookersCard = (): PageElement => cy.get('[data-test="administer-bookers"]')
}
Loading

0 comments on commit 01b2b1b

Please sign in to comment.