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

ADJUST1-495 DR: UAL banner #219

Merged
merged 3 commits into from
Mar 12, 2024
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/ada.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ context('Enter an ADA', () => {
submit.submitButton().click()

const hub = HubPage.verifyOnPage(HubPage)
hub.successMessage().contains('ADA updates have been saved')
hub.successMessage().contains('ADA details have been updated')
})
})
6 changes: 3 additions & 3 deletions integration_tests/e2e/rada.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ context('Enter a RADA', () => {
const review = ReviewPage.verifyOnPage(ReviewPage)
review.submit().click()
hub = HubPage.verifyOnPage(HubPage)
hub.successMessage().contains('25 days of RADA have been added')
hub.successMessage().contains('25 days of RADA have been saved')
})

it('Add a RADA when no ADAs exist produces error message', () => {
Expand Down Expand Up @@ -73,7 +73,7 @@ context('Enter a RADA', () => {
const review = ReviewPage.verifyOnPage(ReviewPage)
review.submit().click()
hub = HubPage.verifyOnPage(HubPage)
hub.successMessage().contains('26 days of RADA have been update')
hub.successMessage().contains('RADA details have been updated')
})

it('View and remove a RADA', () => {
Expand All @@ -86,6 +86,6 @@ context('Enter a RADA', () => {
const removePage = RemovePage.verifyOnPage<RemovePage>(RemovePage, 'Are you sure you want to remove RADA')
removePage.removeButton().click()
hub = HubPage.verifyOnPage(HubPage)
hub.successMessage().contains('25 days of RADA have been removed')
hub.successMessage().contains('25 days of RADA have been deleted')
})
})
56 changes: 19 additions & 37 deletions server/model/adjustmentsHubViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@ import { calculateReleaseDatesCheckInformationUrl } from '../utils/utils'
import adjustmentTypes, { AdjustmentType } from './adjustmentTypes'

export type Message = {
type: string
type: AdjustmentType
days: number
text: string
action:
| 'CREATE'
| 'REMOVE'
| 'UPDATE'
| 'REJECTED'
| 'VALIDATION'
| 'ADDITIONAL_DAYS_UPDATED'
| 'REMAND_ADDED'
| 'REMAND_UPDATED'
| 'REMAND_REMOVED'
| 'TAGGED_BAIL_ADDED'
| 'TAGGED_BAIL_UPDATED'
| 'TAGGED_BAIL_REMOVED'
action: MessageAction
}

export type MessageAction = 'CREATE' | 'REMOVE' | 'UPDATE' | 'REJECTED' | 'VALIDATION'

export default class AdjustmentsHubViewModel {
public adjustmentTypes = adjustmentTypes

Expand All @@ -35,7 +26,7 @@ export default class AdjustmentsHubViewModel {
public message: Message,
public serviceHasCalculatedUnusedDeductions: boolean,
) {
this.messageType = message && this.adjustmentTypes.find(it => it.value === message.type)
this.messageType = message && this.adjustmentTypes.find(it => it.value === message.type.value)
}

public deductions(): AdjustmentType[] {
Expand Down Expand Up @@ -88,36 +79,27 @@ export default class AdjustmentsHubViewModel {
return this.getTotalDays(adjustmentType) !== 0
}

public isRemandOrTaggedBailAction(): boolean {
return [
'REMAND_ADDED',
'REMAND_UPDATED',
'REMAND_REMOVED',
'TAGGED_BAIL_ADDED',
'TAGGED_BAIL_UPDATED',
'TAGGED_BAIL_REMOVED',
].includes(this.message.action)
public isAddEditDelete(): boolean {
return ['CREATE', 'REMOVE', 'UPDATE'].includes(this.message.action)
}

public getNotificationBannerHeading(): string {
if (!this.message || !this.message.action) {
public getNotificationBannerHeadingForAddEditDelete(): string {
if (!this.message || !this.message.action || !this.message.type) {
return null
}

let type = ''
if (this.message.action.indexOf('REMAND') > -1) {
type = 'Remand'
} else if (this.message.action.indexOf('TAGGED_BAIL') > -1) {
type = 'Tagged bail'
}
const useShortText =
this.message.type.value.indexOf('UNLAWFULLY_AT_LARGE') > -1 ||
this.message.type.value.indexOf('RESTORATION_OF_ADDITIONAL_DAYS_AWARDED') > -1 ||
this.message.type.value.indexOf('ADDITIONAL_DAYS_AWARDED') > -1

let heading
if (this.message.action.indexOf('ADDED') > -1) {
heading = `${this.message.days} ${this.message.days > 1 ? 'days' : 'day'} of ${type.toLowerCase()} ${this.message.days > 1 ? 'have' : 'has'} been saved`
} else if (this.message.action.indexOf('REMOVED') > -1) {
heading = `${this.message.days} ${this.message.days > 1 ? 'days' : 'day'} of ${type.toLowerCase()} ${this.message.days > 1 ? 'have' : 'has'} been deleted`
if (this.message.action === 'CREATE') {
heading = `${this.message.days} ${this.message.days > 1 ? 'days' : 'day'} of ${this.message.type.shortText} ${this.message.days > 1 ? 'have' : 'has'} been saved`
} else if (this.message.action === 'REMOVE') {
heading = `${this.message.days} ${this.message.days > 1 ? 'days' : 'day'} of ${this.message.type.shortText} ${this.message.days > 1 ? 'have' : 'has'} been deleted`
} else {
heading = `${type} details have been updated`
heading = `${useShortText ? this.message.type.shortText : this.message.type.text} details have been updated`
}

return heading
Expand Down
10 changes: 8 additions & 2 deletions server/routes/additionalDaysAwardedRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { AdaIntercept, AdasToReview } from '../@types/AdaTypes'
import AdjustmentsClient from '../api/adjustmentsClient'
import { Message } from '../model/adjustmentsHubViewModel'
import PadaForm from '../model/padaForm'
import adjustmentTypes, { AdjustmentType } from '../model/adjustmentTypes'

export default class AdditionalDaysAwardedRoutes {
private additionalDaysAwardedAdjustmentType: AdjustmentType

constructor(
private readonly prisonerService: PrisonerService,
private readonly additionalDaysAwardedService: AdditionalDaysAwardedService,
) {}
) {
this.additionalDaysAwardedAdjustmentType = adjustmentTypes.find(it => it.value === 'ADDITIONAL_DAYS_AWARDED')
}

public intercept: RequestHandler = async (req, res): Promise<void> => {
const { token } = res.locals.user
Expand Down Expand Up @@ -165,7 +170,8 @@ export default class AdditionalDaysAwardedRoutes {
)

const message = {
action: 'ADDITIONAL_DAYS_UPDATED',
type: this.additionalDaysAwardedAdjustmentType,
action: 'UPDATE',
} as Message
return res.redirect(`/${nomsId}/success?message=${JSON.stringify(message)}`)
}
Expand Down
12 changes: 3 additions & 9 deletions server/routes/adjustmentRoutes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,7 @@ describe('Adjustment routes tests', () => {
.expect(302)
.expect(
'Location',
`/${NOMS_ID}/success?message=${encodeURI(
'{"type":"RESTORATION_OF_ADDITIONAL_DAYS_AWARDED","days":24,"action":"CREATE"}',
)}`,
`/${NOMS_ID}/success?message=%7B%22type%22:%7B%22value%22:%22RESTORATION_OF_ADDITIONAL_DAYS_AWARDED%22,%22text%22:%22RADA%20(Restoration%20of%20added%20days)%22,%22alternativeText%22:%22RADA%22,%22shortText%22:%22RADA%22,%22url%22:%22restored-additional-days%22%7D,%22days%22:24,%22action%22:%22CREATE%22%7D`,
)
.expect(res => {
expect(adjustmentsService.create.mock.calls).toHaveLength(1)
Expand All @@ -551,9 +549,7 @@ describe('Adjustment routes tests', () => {
.expect(302)
.expect(
'Location',
`/${NOMS_ID}/success?message=${encodeURI(
'{"type":"RESTORATION_OF_ADDITIONAL_DAYS_AWARDED","days":24,"action":"UPDATE"}',
)}`,
`/${NOMS_ID}/success?message=%7B%22type%22:%7B%22value%22:%22RESTORATION_OF_ADDITIONAL_DAYS_AWARDED%22,%22text%22:%22RADA%20(Restoration%20of%20added%20days)%22,%22alternativeText%22:%22RADA%22,%22shortText%22:%22RADA%22,%22url%22:%22restored-additional-days%22%7D,%22days%22:24,%22action%22:%22UPDATE%22%7D`,
)
.expect(res => {
expect(adjustmentsService.update.mock.calls).toHaveLength(1)
Expand Down Expand Up @@ -606,9 +602,7 @@ describe('Adjustment routes tests', () => {
.expect(302)
.expect(
'Location',
`/${NOMS_ID}/success?message=${encodeURI(
'{"type":"RESTORATION_OF_ADDITIONAL_DAYS_AWARDED","days":24,"action":"REMOVE"}',
)}`,
`/${NOMS_ID}/success?message=%7B%22type%22:%7B%22value%22:%22RESTORATION_OF_ADDITIONAL_DAYS_AWARDED%22,%22text%22:%22RADA%20(Restoration%20of%20added%20days)%22,%22alternativeText%22:%22RADA%22,%22shortText%22:%22RADA%22,%22url%22:%22restored-additional-days%22%7D,%22days%22:24,%22action%22:%22REMOVE%22%7D`,
)
.expect(res => {
expect(adjustmentsService.delete.mock.calls).toHaveLength(1)
Expand Down
19 changes: 6 additions & 13 deletions server/routes/adjustmentRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ export default class AdjustmentRoutes {
} else {
await this.adjustmentsService.create([adjustment], token)
}

const message = {
type: adjustment.adjustmentType,
type: adjustmentTypes.find(it => it.value === adjustment.adjustmentType),
days: adjustment.days || daysBetween(new Date(adjustment.fromDate), new Date(adjustment.toDate)),
action: adjustment.id ? 'UPDATE' : 'CREATE',
} as Message
Expand Down Expand Up @@ -322,19 +323,10 @@ export default class AdjustmentRoutes {

const adjustment = await this.adjustmentsService.get(id, token)
await this.adjustmentsService.delete(id, token)
let action
if (adjustment.adjustmentType === 'REMAND') {
action = 'REMAND_REMOVED'
} else if (adjustment.adjustmentType === 'TAGGED_BAIL') {
action = 'TAGGED_BAIL_REMOVED'
} else {
action = 'REMOVE'
}

const message = JSON.stringify({
type: adjustment.adjustmentType,
type: adjustmentTypes.find(it => it.value === adjustment.adjustmentType),
days: adjustment.days,
action,
action: 'REMOVE',
} as Message)
return res.redirect(`/${nomsId}/success?message=${message}`)
}
Expand Down Expand Up @@ -365,7 +357,8 @@ export default class AdjustmentRoutes {
}
await this.adjustmentsService.restore({ ids: recallForm.getSelectedAdjustments() }, token)
const message = {
action: 'REMAND_UPDATED',
type: adjustmentTypes.find(it => it.value === 'REMAND'),
action: 'UPDATE',
} as Message
return res.redirect(`/${nomsId}/success?message=${JSON.stringify(message)}`)
}
Expand Down
15 changes: 12 additions & 3 deletions server/routes/remandRoutes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,10 @@ describe('Remand routes tests', () => {
return request(app)
.post(`/${NOMS_ID}/remand/save`)
.expect(302)
.expect('Location', `/${NOMS_ID}/success?message=%7B%22action%22:%22REMAND_ADDED%22,%22days%22:10%7D`)
.expect(
'Location',
`/${NOMS_ID}/success?message=%7B%22type%22:%7B%22value%22:%22REMAND%22,%22text%22:%22Remand%22,%22shortText%22:%22remand%22,%22url%22:%22remand%22%7D,%22action%22:%22CREATE%22,%22days%22:10%7D`,
)
})

it('GET /{nomsId}/remand/remove', () => {
Expand Down Expand Up @@ -650,7 +653,10 @@ describe('Remand routes tests', () => {
return request(app)
.post(`/${NOMS_ID}/remand/remove/${ADJUSTMENT_ID}`)
.expect(302)
.expect('Location', `/${NOMS_ID}/success?message=%7B%22type%22:%22REMAND%22,%22action%22:%22REMAND_REMOVED%22%7D`)
.expect(
'Location',
`/${NOMS_ID}/success?message=%7B%22type%22:%7B%22value%22:%22REMAND%22,%22text%22:%22Remand%22,%22shortText%22:%22remand%22,%22url%22:%22remand%22%7D,%22action%22:%22REMOVE%22%7D`,
)
})

it('GET /{nomsId}/remand/edit with successful unused deductions calculation', () => {
Expand Down Expand Up @@ -774,7 +780,10 @@ describe('Remand routes tests', () => {
return request(app)
.post(`/${NOMS_ID}/remand/edit/${SESSION_ID}`)
.expect(302)
.expect('Location', `/${NOMS_ID}/success?message=%7B%22action%22:%22REMAND_UPDATED%22%7D`)
.expect(
'Location',
`/${NOMS_ID}/success?message=%7B%22type%22:%7B%22value%22:%22REMAND%22,%22text%22:%22Remand%22,%22shortText%22:%22remand%22,%22url%22:%22remand%22%7D,%22action%22:%22UPDATE%22%7D`,
)
})

it('GET /{nomsId}/remand/edit/:id No save button because of no changes made', () => {
Expand Down
13 changes: 10 additions & 3 deletions server/routes/remandRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ import { Message } from '../model/adjustmentsHubViewModel'
import RemandDatesModel from '../model/remandDatesModel'
import RemandViewModel from '../model/remandViewModel'
import RemandChangeModel from '../model/remandChangeModel'
import adjustmentTypes, { AdjustmentType } from '../model/adjustmentTypes'

export default class RemandRoutes {
private remandAdjustmentType: AdjustmentType

constructor(
private readonly prisonerService: PrisonerService,
private readonly adjustmentsService: AdjustmentsService,
private readonly adjustmentsStoreService: AdjustmentsStoreService,
private readonly calculateReleaseDatesService: CalculateReleaseDatesService,
) {}
) {
this.remandAdjustmentType = adjustmentTypes.find(it => it.value === 'REMAND')
}

public add: RequestHandler = async (req, res): Promise<void> => {
const { token } = res.locals.user
Expand Down Expand Up @@ -255,7 +260,8 @@ export default class RemandRoutes {
)

const message = {
action: 'REMAND_ADDED',
type: this.remandAdjustmentType,
action: 'CREATE',
days,
} as Message
return res.redirect(`/${nomsId}/success?message=${JSON.stringify(message)}`)
Expand Down Expand Up @@ -363,7 +369,8 @@ export default class RemandRoutes {
await this.adjustmentsService.update(id, adjustment, token)

const message = {
action: 'REMAND_UPDATED',
type: this.remandAdjustmentType,
action: 'UPDATE',
} as Message
return res.redirect(`/${nomsId}/success?message=${JSON.stringify(message)}`)
}
Expand Down
5 changes: 4 additions & 1 deletion server/routes/taggedBailRoutes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ describe('Tagged bail routes tests', () => {
return request(app)
.post(`/${NOMS_ID}/tagged-bail/review/add/${SESSION_ID}`)
.expect(302)
.expect('Location', `/${NOMS_ID}/success?message=%7B%22action%22:%22TAGGED_BAIL_ADDED%22,%22days%22:9955%7D`)
.expect(
'Location',
`/${NOMS_ID}/success?message=%7B%22type%22:%7B%22value%22:%22TAGGED_BAIL%22,%22text%22:%22Tagged%20bail%22,%22shortText%22:%22tagged%20bail%22,%22url%22:%22tagged-bail%22%7D,%22action%22:%22CREATE%22,%22days%22:9955%7D`,
)
})

test.each`
Expand Down
13 changes: 10 additions & 3 deletions server/routes/taggedBailRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ import {
import CalculateReleaseDatesService from '../services/calculateReleaseDatesService'
import TaggedBailChangeModel from '../model/taggedBailEditModel'
import TaggedBailRemoveModel from '../model/taggedBailRemoveModel'
import adjustmentTypes, { AdjustmentType } from '../model/adjustmentTypes'

export default class TaggedBailRoutes {
private taggedBailAdjustmentType: AdjustmentType

constructor(
private readonly prisonerService: PrisonerService,
private readonly adjustmentsService: AdjustmentsService,
private readonly adjustmentsStoreService: AdjustmentsStoreService,
private readonly calculateReleaseDatesService: CalculateReleaseDatesService,
) {}
) {
this.taggedBailAdjustmentType = adjustmentTypes.find(it => it.value === 'TAGGED_BAIL')
}

public add: RequestHandler = async (req, res): Promise<void> => {
const { nomsId } = req.params
Expand Down Expand Up @@ -198,7 +203,8 @@ export default class TaggedBailRoutes {
await this.adjustmentsService.create([adjustment], token)

const message = {
action: 'TAGGED_BAIL_ADDED',
type: this.taggedBailAdjustmentType,
action: 'CREATE',
days: adjustment.days,
} as Message
return res.redirect(`/${nomsId}/success?message=${JSON.stringify(message)}`)
Expand Down Expand Up @@ -266,7 +272,8 @@ export default class TaggedBailRoutes {
await this.adjustmentsService.update(id, adjustment, token)

const message = {
action: 'TAGGED_BAIL_UPDATED',
type: this.taggedBailAdjustmentType,
action: 'UPDATE',
} as Message
return res.redirect(`/${nomsId}/success?message=${JSON.stringify(message)}`)
}
Expand Down
Loading