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

Man 36 sentence requirements #258

Merged
merged 5 commits into from
Jan 14, 2025
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
2 changes: 1 addition & 1 deletion integration_tests/e2e/compliance.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ context('Compliance', () => {
page.getRowData('breach1', 'startDate', 'Value').should('contain.text', '2 March 2020')
page.getRowData('breach1', 'status', 'Value').should('contain.text', 'An active breach status')

page.getCardHeader('activity1').should('contain.text', '10 days RAR, 9 completed')
page.getCardHeader('activity1').should('contain.text', '9 of 10 RAR days completed')
page.getRowData('activity1', 'appointments', 'Value').should('contain.text', '1 national standard appointments')
page.getRowData('activity1', 'withoutOutcome', 'Value').should('contain.text', '3 without a recorded outcome')

Expand Down
6 changes: 4 additions & 2 deletions integration_tests/e2e/overview.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ context('Overview', () => {
.should('contain.text', 'Committed/ Transferred to Crown: Life imprisonment (Adult)')
page.getRowData('personalDetails', 'disabilities', 'Value').should('contain.text', 'Dyslexia, Arthritis')
page.getRowData('personalDetails', 'adjustments', 'Value').should('contain.text', 'Hand Rails, Special Furniture')
page.getCardHeader('sentence2').should('contain.text', 'ORA Community Order')
page
.getRowData('sentence2', 'mainOffence', 'Value')
.should(
'contain.text',
'(Having possession a picklock or other implement with intent to break into any premises - 18502)',
)
page.getRowData('sentence2', 'order', 'Value').should('contain.text', 'ORA Community Order')
page.getRowData('sentence2', 'requirements', 'Value').should('contain.text', '10 days RAR, 9 completed')
page.getRowData('sentence2', 'requirements', 'Value').should('contain.text', '9 of 10 RAR days completed')
page.getCardHeader('sentence3').should('contain.text', '12 month Community order')
page
.getRowData('sentence3', 'mainOffence', 'Value')
.should('contain.text', 'Breach of Restraining Order (Protection from Harassment Act 1997) - 00831')
page.getRowData('sentence3', 'order', 'Value').should('contain.text', '12 month Community order')
page.getRowData('sentence3', 'requirements', 'Value').should('contain.text', '16 days RAR, 14 completed')
page.getRowData('sentence3', 'requirements', 'Value').should('contain.text', '14 of 16 RAR days completed')
page
.getRowData('activityAndCompliance', 'previousOrders', 'Value')
.should('contain.text', '1 previous orders (No breaches on previous orders)')
Expand Down
38 changes: 38 additions & 0 deletions integration_tests/e2e/requirement-note.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Page from '../pages/page'
import SentencePage from '../pages/sentence'

context('Sentence', () => {
it('Requirement note page is rendered', () => {
cy.visit('/case/X000001/sentence/requirement/1/note/0')
const page = Page.verifyOnPage(SentencePage)
page.headerCrn().should('contain.text', 'X000001')
page.headerName().should('contain.text', 'Caroline Wolff')
cy.get('[data-qa=pageHeading]').eq(0).should('contain.text', 'Sentence')

cy.get(`[class=app-summary-card__header]`).within(() =>
cy.get('h2').should('contain.text', '1 of 12 RAR days completed'),
)

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').should('have.length', 6))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').should('have.length', 6))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(0).should('contain.text', 'Length of RAR'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(0).should('contain.text', '12 days'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(1).should('contain.text', 'Completed RAR'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(1).should('contain.text', '1 day'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(2).should('contain.text', 'Start date'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(2).should('contain.text', '12 April 2024'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(3).should('contain.text', 'Note added by'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(3).should('contain.text', 'Jon Jones'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(4).should('contain.text', 'Date added'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(4).should('contain.text', '21 August 2024'))

cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dt').eq(5).should('contain.text', 'Note'))
cy.get(`[class=app-summary-card__body]`).within(() => cy.get('dd').eq(5).should('contain.text', '123456'))
})
})
52 changes: 51 additions & 1 deletion integration_tests/e2e/sentence.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ context('Sentence', () => {
const page = Page.verifyOnPage(SentencePage)
page.headerCrn().should('contain.text', 'X000001')
page.headerName().should('contain.text', 'Caroline Wolff')
cy.get('[data-qa=pageHeading]').eq(0).should('contain.text', 'Sentence')

page.getTab('overview').should('contain.text', 'Overview')
page.getTab('personalDetails').should('contain.text', 'Personal details')
Expand Down Expand Up @@ -193,4 +192,55 @@ context('Sentence', () => {
cy.get('[data-qa="convictionCard"]').should('not.exist')
cy.get('[data-qa="offenceCard"]').should('not.exist')
})

it('Sentence page is rendered with requirements', () => {
cy.visit('/case/X000001/sentence?number=1')
const page = Page.verifyOnPage(SentencePage)

cy.get(`[data-qa="sentenceCard"]`).within(() => cy.get('dt').eq(5).should('contain.text', 'Requirements'))
cy.get(`[data-qa="requirementsValue"]`).within(() =>
cy.get('details').eq(0).should('contain.text', '1 of 12 RAR days completed'),
)
cy.get(`[data-qa="requirementsValue"]`).within(() =>
cy.get('details').eq(1).should('contain.text', 'Curfew (Electronic Monitored)'),
)
cy.get(`[data-qa="requirementsValue"]`).within(() =>
cy.get('details').eq(2).should('contain.text', 'Unpaid Work - Regular'),
)
cy.get(`[data-qa="requirementsValue"] `).within(() => cy.get('details').eq(1).click())
page.getRequirementLabel(2, 1).should('contain.text', 'Length')
page.getRequirementValue(2, 1).should('contain.text', '10 hours')
page.getRequirementLabel(2, 2).should('contain.text', 'Start date')
page.getRequirementValue(2, 2).should('contain.text', '12 January 2024')
page.getRequirementLabel(2, 3).should('contain.text', 'End date')
page.getRequirementValue(2, 3).should('contain.text', '9 January 2024')
page.getRequirementLabel(2, 4).should('contain.text', 'Result')
page.getRequirementValue(2, 4).should('contain.text', 'Expired (Normal)')
page.getRequirementLabel(2, 5).should('contain.text', 'Notes')
page.getRequirementValue(2, 5).should('contain.text', 'curfew notes')
page
.getRequirementValue(2, 5)
.find('p:nth-of-type(2)')
.should('contain.text', 'Comment added by Jon Jones on 21 August 2024')
page.getRequirementValue(2, 5).find('a').should('not.exist')

cy.get(`[data-qa="requirementsValue"] `).within(() => cy.get('details').eq(0).click())
page.getRequirementLabel(1, 1).should('contain.text', 'Length of RAR')
page.getRequirementValue(1, 1).should('contain.text', '12 days')
page.getRequirementLabel(1, 2).should('contain.text', 'Completed RAR')
page.getRequirementValue(1, 2).should('contain.text', '1 day')
page.getRequirementLabel(1, 3).should('contain.text', 'Start date')
page.getRequirementValue(1, 3).should('contain.text', '12 April 2024')
page.getRequirementLabel(1, 4).should('contain.text', 'Notes')
page.getRequirementValue(1, 4).should('contain.text', 'Requirement created automatically')
page.getRequirementValue(1, 4).should('not.contain.text', '123456')
page.getRequirementValue(1, 4).find('a').should('contain.text', 'View full note')
page
.getRequirementValue(1, 4)
.find('p:nth-of-type(2)')
.should('contain.text', 'Comment added by Jon Jones on 21 August 2024')
page.getRequirementValue(1, 4).find('a').click()
cy.get(`[data-qa="name"]`).should('contain.text', 'Caroline Wolff')
cy.get('.app-summary-card__header').should('contain.text', '1 of 12 RAR days completed')
})
})
2 changes: 1 addition & 1 deletion integration_tests/pages/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default abstract class Page {
}

checkOnPage(): void {
cy.get('h1').contains(this.title)
cy.get('[data-qa=pageHeading]').contains(this.title)
}

signOut = (): PageElement => cy.get('[data-qa=signOut]')
Expand Down
10 changes: 10 additions & 0 deletions integration_tests/pages/sentence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ export default class SentencePage extends Page {
activeSideNavItem = (): PageElement => cy.get('.moj-side-navigation__item--active a')

noActiveSentence = (): PageElement => cy.get('[data-qa="no-active-sentence"]')

getRequirementLabel = (requirementIndex: number, index: number): PageElement =>
cy.get(
`[data-qa="requirementsValue"] details:nth-of-type(${requirementIndex}) .govuk-summary-list__row:nth-of-type(${index}) dt`,
)

getRequirementValue = (requirementIndex: number, index: number): PageElement =>
cy.get(
`[data-qa="requirementsValue"] details:nth-of-type(${requirementIndex}) .govuk-summary-list__row:nth-of-type(${index}) dd`,
)
}
12 changes: 12 additions & 0 deletions server/data/masApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ProfessionalContact } from './model/professionalContact'
import { CaseAccess, UserAccess } from './model/caseAccess'
import { LicenceConditionNoteDetails } from './model/licenceConditionNoteDetails'
import { AppointmentRequestBody } from '../@types'
import { RequirementNoteDetails } from './model/requirementNoteDetails'

export default class MasApiClient extends RestClient {
constructor(token: string) {
Expand Down Expand Up @@ -64,6 +65,17 @@ export default class MasApiClient extends RestClient {
})
}

async getSentenceRequirementNote(
crn: string,
requirementId: string,
noteId: string,
): Promise<RequirementNoteDetails | null> {
return this.get({
path: `/sentence/${crn}/requirement/${requirementId}/note/${noteId}`,
handle404: false,
})
}

async getContacts(crn: string): Promise<ProfessionalContact | null> {
return this.get({ path: `/sentence/${crn}/contacts`, handle404: false })
}
Expand Down
32 changes: 32 additions & 0 deletions server/data/model/requirementNoteDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PersonSummary } from './common'

export interface RequirementNoteDetails {
personSummary: PersonSummary
requirement: Requirement
}

export interface Requirement {
code: string
expectedStartDate?: string
actualStartDate: string
expectedEndDate?: string
actualEndDate?: string
terminationReason?: string
description: string
length: number
lengthUnitValue: string
requirementNote: RequirementNote
rar?: {
completed: number
scheduled: number
totalDays: number
}
}

export interface RequirementNote {
id: string
createdBy: string
createdByDate: string
note: string
hasNotesBeenTruncated: boolean
}
11 changes: 10 additions & 1 deletion server/data/model/sentenceDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ export interface Order {
startDate: string
}

export interface RequirementNote {
id: number
createdBy: string
createdByDate: string
note: string
hasNoteBeenTruncated: boolean
}

export interface Requirement {
id?: number
id: number
code: string
expectedStartDate: string
actualStartDate: string
Expand All @@ -64,6 +72,7 @@ export interface Requirement {
description: string
codeDescription: string
length: string
requirementNotes: RequirementNote[]
notes: string
rar: Rar
}
Expand Down
27 changes: 27 additions & 0 deletions server/routes/sentence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,31 @@ export default function sentenceRoutes(router: Router, { hmppsAuthClient }: Serv
crn,
})
})

get('/case/:crn/sentence/requirement/:requirementId/note/:noteId', async (req, res, _next) => {
const { crn, requirementId, noteId } = req.params
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username)

await auditService.sendAuditMessage({
action: 'VIEW_MAS_SENTENCE_REQUIREMENT_NOTE',
who: res.locals.user.username,
subjectId: crn,
subjectType: 'CRN',
correlationId: v4(),
service: 'hmpps-manage-a-supervision-ui',
})

const masClient = new MasApiClient(token)
const tierClient = new TierApiClient(token)

const [requirementNoteDetails, tierCalculation] = await Promise.all([
masClient.getSentenceRequirementNote(crn, requirementId, noteId),
tierClient.getCalculationDetails(crn),
])
res.render('pages/requirement-note', {
requirementNoteDetails,
tierCalculation,
crn,
})
})
}
2 changes: 1 addition & 1 deletion server/views/pages/address-book-professional.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% endblock %}

{% block content %}
<h1 class="govuk-heading-xl">{{ title }}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{ title }}</h1>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/appointments/appointment.njk
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl govuk-!-margin-bottom-6">
<h1 class="govuk-heading-xl govuk-!-margin-bottom-6" data-qa="pageHeading">
<span class="govuk-caption-xl" data-qa="appointmentType">
{% include './_appointment-prefix.njk' %}</span>
<span data-qa="appointmentTitle">{{ title }}</span>
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/caseload/caseload.njk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% endif %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<h1 class="govuk-heading-xl">
<h1 class="govuk-heading-xl" data-qa="pageHeading">
{{ title }}
</h1>
{% include "./caseload-nav.njk" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% if sentence.rar and sentence.rarCategory %}
{% set queryParams = '?requirement=' + sentence.rarCategory | toSlug %}
{% set requirements %}
{{ sentence.rar.totalDays }} days RAR, {{ sentence.rar.completed }} completed
{{ sentence.rar.completed }} of {{ sentence.rar.totalDays }} RAR days completed
{% endset %}
{% else %}
{% set requirements = false %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/handoff/delius.njk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">{{title}}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{title}}</h1>

<p>You’ll need to use National Delius to:</p>
<ul class="govuk-list govuk-list--bullet">
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/handoff/oasys.njk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">{{title}}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{title}}</h1>

<p>You’ll need to use OASys to:</p>
<ul class="govuk-list govuk-list--bullet">
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% set mainClasses = "app-container govuk-body" %}

{% block content %}
<h1 class="govuk-heading-l">Manage a Supervision</h1>
<h1 class="govuk-heading-l" data-qa="pageHeading">Manage a Supervision</h1>
<div class="govuk-grid-column-two-thirds">
<p>Not all cases are suitable for the Manage supervisions pilot. This service is only suitable for cases that have:</p>
<ul class="govuk-list govuk-list--bullet">
Expand Down
4 changes: 2 additions & 2 deletions server/views/pages/overview.njk
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
{% endset %}
{% set requirements %}
{% if sentence.rar %}
{{ sentence.rar.totalDays }} days RAR, {{ sentence.rar.completed }} completed
{{ sentence.rar.completed }} of {{ sentence.rar.totalDays }} RAR days completed
{% endif %}
{% endset %}
{% set mainOffence %}
Expand Down Expand Up @@ -322,7 +322,7 @@
{% endset %}

{{ appSummaryCard({
titleText: 'Sentence (' + sentence.eventNumber + ')',
titleText: sentence.order.description,
classes: 'govuk-!-margin-bottom-6 app-summary-card--large-title',
attributes: {'data-qa': 'sentence' + sentence.eventNumber + 'Card'},
html: sentenceHtml,
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details/addresses.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% endblock %}

{% block content %}
<h1 class="govuk-heading-xl">{{ title }}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{ title }}</h1>


<!-- {{ govukWarningText({
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details/adjustments.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% endblock %}

{% block content %}
<h1 class="govuk-heading-xl">{{title}}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{title}}</h1>

{% for adjustment in adjustments.provisions %}
{% set adjustmentsHtml %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details/circumstances.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% endblock %}

{% block content %}
<h1 class="govuk-heading-xl">{{title}}</h1>
<h1 class="govuk-heading-xl" data-qa="pageHeading">{{title}}</h1>

{% for circumstance in circumstances.circumstances %}
{% set circumstanceHtml %}
Expand Down
2 changes: 1 addition & 1 deletion server/views/pages/personal-details/contact.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-xl">
<h1 class="govuk-heading-xl" data-qa="pageHeading">
<span data-qa="contactRelationshipTypeHeaderValue" class="govuk-caption-xl">{{ personalContact.relationshipType }}</span>
<span data-qa="contactNameHeaderValue">{{ title }}</span>
</h1>
Expand Down
Loading
Loading