generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for booker management
- Loading branch information
Showing
13 changed files
with
366 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] }, | ||
}, | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.