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-44 - Prisoner contacts #84

Merged
merged 6 commits into from
Mar 30, 2023
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
51 changes: 50 additions & 1 deletion integration_tests/e2e/personalPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ context('When signed in', () => {
cy.task('stubPrisonerDetail', 'G6123VU')
cy.task('stubSecondaryLanguages', 1102484)
cy.task('stubProperty', 1102484)
cy.task('stubAddresses', 1102484)
cy.task('stubAddresses', 'G6123VU')
cy.task('stubOffenderContacts', 'G6123VU')
cy.task('stubPersonAddresses')
})

it('displays the personal details page', () => {
Expand Down Expand Up @@ -131,4 +133,51 @@ context('When signed in', () => {
page.addresess().addedOn().should('include.text', '1 May 2020')
})
})

context('Emergency contacts and next of kin', () => {
it('Displays the contacts', () => {
const page = visitPersonalDetailsPage()

const addressShouldIncludeCorrectText = contact => {
contact.address().should('include.text', 'Flat 7, premises address, street field')
contact.address().should('include.text', 'Leeds')
contact.address().should('include.text', 'LS1 AAA')
contact.address().should('include.text', 'England')

contact.addressTypes().should('include.text', 'Discharge - Permanent Housing')
contact.addressTypes().should('include.text', 'HDC Address')
contact.addressTypes().should('include.text', 'Other')

contact.addressPhones().should('include.text', '4444555566')
contact.addressPhones().should('include.text', '0113444444')
contact.addressPhones().should('include.text', '0113 333444')
contact.addressPhones().should('include.text', '0800 222333')
}

const firstContact = page.contacts().contact(0)
addressShouldIncludeCorrectText(firstContact)
firstContact.name().should('include.text', 'First Name Middle Name Surname')
firstContact.emergencyContact().should('be.visible')
firstContact.relationship().should('include.text', 'Grandson')
firstContact.emails().should('include.text', 'Not entered')

const secondContact = page.contacts().contact(1)
addressShouldIncludeCorrectText(secondContact)
secondContact.name().should('include.text', 'First Name Middle Name Bob')
secondContact.emergencyContact().should('be.visible')
secondContact.relationship().should('include.text', 'Cousin')
secondContact.emails().should('include.text', 'Not entered')
secondContact.phones().should('include.text', '555555 6666666')

const thirdContact = page.contacts().contact(2)
addressShouldIncludeCorrectText(thirdContact)
thirdContact.name().should('include.text', 'Dom Bull')
thirdContact.relationship().should('include.text', 'Grandfather')
thirdContact.emails().should('include.text', 'email@addressgoeshere.com')
thirdContact.emails().should('include.text', 'email2@address.com')
thirdContact.phones().should('include.text', '0113222333')
thirdContact.phones().should('include.text', '0113333444')
thirdContact.phones().should('include.text', '07711333444')
})
})
})
41 changes: 37 additions & 4 deletions integration_tests/mockApis/prison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { prisonerDetailMock } from '../../server/data/localMockData/prisonerDeta
import { secondaryLanguagesMock } from '../../server/data/localMockData/secondaryLanguages'
import { propertyMock } from '../../server/data/localMockData/property'
import { mockAddresses } from '../../server/data/localMockData/addresses'
import { mockOffenderContacts } from '../../server/data/localMockData/offenderContacts'
import { CaseNotesByTypeA } from '../../server/data/localMockData/caseNotes'
import { offenderContact } from '../../server/data/localMockData/offenderContacts'
import { mockContactDetail } from '../../server/data/localMockData/contactDetail'
import { mapToQueryString } from '../../server/utils/utils'
import {
emptyAlertsMock,
Expand Down Expand Up @@ -156,7 +157,7 @@ export default {
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: offenderContact,
jsonBody: mockContactDetail,
},
})
},
Expand Down Expand Up @@ -224,11 +225,43 @@ export default {
})
},

stubAddresses: (bookingId: number) => {
stubAddresses: (prisonerNumber: string) => {
return stubFor({
request: {
method: 'GET',
urlPattern: `/prison/api/bookings/${bookingId}/addresses`,
urlPattern: `/prison/api/offenders/${prisonerNumber}/addresses`,
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: mockAddresses,
},
})
},

stubOffenderContacts: (prisonerNumber: string) => {
return stubFor({
request: {
method: 'GET',
urlPattern: `/prison/api/offenders/${prisonerNumber}/contacts`,
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: mockOffenderContacts,
},
})
},

stubPersonAddresses: () => {
return stubFor({
request: {
method: 'GET',
urlPattern: '/prison/api/persons/(\\d*)/addresses',
},
response: {
status: 200,
Expand Down
21 changes: 21 additions & 0 deletions integration_tests/pages/personalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,25 @@ export default class PersonalPage extends Page {
addedOn: () => cardData().find('[data-qa=address-added-on]'),
}
}

contacts = () => {
const cardData = () => cy.get('[data-qa=emergency-contacts]')
return {
contact: contactNumber => {
const contactData = () => cardData().find('[data-qa=emergency-contact]').eq(contactNumber)
const details = () => contactData().find('[data-qa=contact-details]').find('.govuk-summary-list__value')

return {
name: () => contactData().find('[data-qa=contact-name]'),
relationship: () => contactData().find('[data-qa=contact-relationship]'),
emergencyContact: () => contactData().find('[data-qa=contact-emergency-contact]'),
phones: () => contactData().find('[data-qa=contact-numbers]'),
emails: () => details().eq(0),
address: () => details().eq(1),
addressPhones: () => details().eq(2),
addressTypes: () => details().eq(3),
}
},
}
}
}
9 changes: 6 additions & 3 deletions server/data/interfaces/prisonApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AdjudicationSummary } from '../../interfaces/adjudicationSummary'
import { VisitSummary } from '../../interfaces/visitSummary'
import { VisitBalances } from '../../interfaces/visitBalances'
import { Assessment } from '../../interfaces/prisonApi/assessment'
import { OffenderContact } from '../../interfaces/staffContacts'
import { ContactDetail } from '../../interfaces/staffContacts'
import { CaseNote } from '../../interfaces/caseNote'
import { ScheduledEvent } from '../../interfaces/scheduledEvent'
import { PrisonerDetail } from '../../interfaces/prisonerDetail'
Expand All @@ -18,6 +18,7 @@ import { SecondaryLanguage } from '../../interfaces/prisonApi/secondaryLanguage'
import { PagedList, PagedListQueryParams } from '../../interfaces/prisonApi/pagedList'
import { PropertyContainer } from '../../interfaces/prisonApi/propertyContainer'
import { Address } from '../../interfaces/prisonApi/address'
import { OffenderContacts } from '../../interfaces/prisonApi/offenderContacts'

export interface PrisonApiClient {
getUserLocations(): Promise<Location[]>
Expand All @@ -28,7 +29,7 @@ export interface PrisonApiClient {
getVisitSummary(bookingId: number): Promise<VisitSummary>
getVisitBalances(prisonerNumber: string): Promise<VisitBalances>
getAssessments(bookingId: number): Promise<Assessment[]>
getOffenderContacts(bookingId: number): Promise<OffenderContact>
getBookingContacts(bookingId: number): Promise<ContactDetail>
getCaseNoteSummaryByTypes(params: object): Promise<CaseNote[]>
getEventsScheduledForToday(bookingId: number): Promise<ScheduledEvent[]>
getPrisoner(prisonerNumber: string): Promise<PrisonerDetail>
Expand All @@ -43,5 +44,7 @@ export interface PrisonApiClient {
getSecondaryLanguages(bookingId: number): Promise<SecondaryLanguage[]>
getAlerts(bookingId: number, queryParams: PagedListQueryParams): Promise<PagedList>
getProperty(bookingId: number): Promise<PropertyContainer[]>
getAddresses(bookingId: number): Promise<Address[]>
getAddresses(prisonerNumber: string): Promise<Address[]>
getAddressesForPerson(personId: number): Promise<Address[]>
getOffenderContacts(prisonerNumber: string): Promise<OffenderContacts>
}
57 changes: 57 additions & 0 deletions server/data/localMockData/contactDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ContactDetail } from '../../interfaces/staffContacts'

export const mockContactDetail: ContactDetail = {
bookingId: 0,
nextOfKin: [
{
lastName: 'SMITH',
firstName: 'JOHN',
middleName: 'MARK',
contactType: 'O',
contactTypeDescription: 'Official',
relationship: 'RO',
relationshipDescription: 'Responsible Officer',
commentText: 'Some additional information',
emergencyContact: true,
nextOfKin: false,
relationshipId: 10466277,
personId: 5871791,
activeFlag: true,
expiryDate: '2019-01-31',
approvedVisitorFlag: true,
canBeContactedFlag: false,
awareOfChargesFlag: true,
contactRootOffenderId: 5871791,
bookingId: 2468081,
createDateTime: '2021-07-05T10:35:17',
},
],
otherContacts: [
{
lastName: 'SMITH',
firstName: 'JOHN',
middleName: 'MARK',
contactType: 'O',
contactTypeDescription: 'Official',
relationship: 'RO',
relationshipDescription: 'Responsible Officer',
commentText: 'Some additional information',
emergencyContact: true,
nextOfKin: false,
relationshipId: 10466277,
personId: 5871791,
activeFlag: true,
expiryDate: '2019-01-31',
approvedVisitorFlag: true,
canBeContactedFlag: false,
awareOfChargesFlag: true,
contactRootOffenderId: 5871791,
bookingId: 2468081,
createDateTime: '2021-07-05T10:35:17',
},
],
}

export default {
offenderContact: mockContactDetail,
}
Loading