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-221 Skip approval page if only PADAS exist - go straight to submit page. Also only show total per charges on view screen #89

Merged
merged 2 commits into from
Oct 27, 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
167 changes: 167 additions & 0 deletions server/routes/additionalDaysAwardedRoutes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import type { Express } from 'express'
import request from 'supertest'
import { appWithAllRoutes, user } from './testutils/appSetup'
import PrisonerService from '../services/prisonerService'
import AdjustmentsService from '../services/adjustmentsService'
import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes'
import IdentifyRemandPeriodsService from '../services/identifyRemandPeriodsService'
import AdjustmentsStoreService from '../services/adjustmentsStoreService'
import AdditionalDaysAwardedService from '../services/additionalDaysAwardedService'
import { AdasToReview } from '../@types/AdaTypes'

jest.mock('../services/adjustmentsService')
jest.mock('../services/prisonerService')
jest.mock('../services/identifyRemandPeriodsService')
jest.mock('../services/adjustmentsStoreService')
jest.mock('../services/additionalDaysAwardedService')

const prisonerService = new PrisonerService(null) as jest.Mocked<PrisonerService>
const adjustmentsService = new AdjustmentsService() as jest.Mocked<AdjustmentsService>
const identifyRemandPeriodsService = new IdentifyRemandPeriodsService() as jest.Mocked<IdentifyRemandPeriodsService>
const adjustmentsStoreService = new AdjustmentsStoreService() as jest.Mocked<AdjustmentsStoreService>
const additionalDaysAwardedService = new AdditionalDaysAwardedService(
null,
null,
) as jest.Mocked<AdditionalDaysAwardedService>

const NOMS_ID = 'ABC123'

const stubbedPrisonerData = {
offenderNo: NOMS_ID,
firstName: 'Anon',
lastName: 'Nobody',
dateOfBirth: '24/06/2000',
bookingId: 12345,
agencyId: 'LDS',
} as PrisonApiPrisoner

const allPadas = {
awaitingApproval: [
{
dateChargeProved: new Date('2023-08-03'),
charges: [
{
chargeNumber: 1525916,
dateChargeProved: new Date('2023-08-03'),
days: 5,
heardAt: 'Moorland (HMP & YOI)',
status: 'PROSPECTIVE',
toBeServed: 'Concurrent',
sequence: 15,
},
{
chargeNumber: 1525917,
dateChargeProved: new Date('2023-08-03'),
days: 5,
heardAt: 'Moorland (HMP & YOI)',
status: 'PROSPECTIVE',
toBeServed: 'Concurrent',
sequence: 16,
},
],
total: 5,
status: 'PENDING APPROVAL',
},
],
suspended: [],
awarded: [],
quashed: [],
totalAwarded: 0,
totalQuashed: 0,
totalAwaitingApproval: 104,
totalSuspended: 0,
intercept: {
number: 2,
type: 'UPDATE',
anyProspective: false,
},
} as AdasToReview

const mixPadasAndPending = {
awaitingApproval: [
{
dateChargeProved: new Date('2023-08-03'),
charges: [
{
chargeNumber: 1525916,
dateChargeProved: new Date('2023-08-03'),
days: 5,
heardAt: 'Moorland (HMP & YOI)',
status: 'PROSPECTIVE',
toBeServed: 'Concurrent',
sequence: 15,
},
{
chargeNumber: 1525917,
dateChargeProved: new Date('2023-08-03'),
days: 5,
heardAt: 'Moorland (HMP & YOI)',
status: 'AWARDED_OR_PENDING',
toBeServed: 'Concurrent',
sequence: 16,
},
],
total: 5,
status: 'PENDING APPROVAL',
},
],
suspended: [],
awarded: [],
quashed: [],
totalAwarded: 0,
totalQuashed: 0,
totalAwaitingApproval: 104,
totalSuspended: 0,
intercept: {
number: 2,
type: 'UPDATE',
anyProspective: false,
},
} as AdasToReview

let app: Express

const defaultUser = user

let userInTest = defaultUser

beforeEach(() => {
app = appWithAllRoutes({
services: {
prisonerService,
adjustmentsService,
identifyRemandPeriodsService,
adjustmentsStoreService,
additionalDaysAwardedService,
},
userSupplier: () => userInTest,
})
})

afterEach(() => {
userInTest = defaultUser
jest.resetAllMocks()
})

describe('Additional Days Awarded routes tests', () => {
describe('Review and approve tests', () => {
it('GET /{nomsId}/additional-days/review-and-approve when only PADAs exist redirects to review and submit', () => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getStartOfSentenceEnvelope.mockResolvedValue(new Date())
additionalDaysAwardedService.getAdasToApprove.mockResolvedValue(allPadas)

return request(app)
.get(`/${NOMS_ID}/additional-days/review-and-approve`)
.expect(302)
.expect('Location', `/${NOMS_ID}/additional-days/review-and-submit`)
})

it('GET /{nomsId}/additional-days/review-and-approve when mix of PADAs and others exist does not redirect', () => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getStartOfSentenceEnvelope.mockResolvedValue(new Date())
additionalDaysAwardedService.getAdasToApprove.mockResolvedValue(mixPadasAndPending)

return request(app).get(`/${NOMS_ID}/additional-days/review-and-approve`).expect(200)
})
})
})
6 changes: 6 additions & 0 deletions server/routes/additionalDaysAwardedRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export default class AdditionalDaysAwardedRoutes {
)
return res.redirect(`/${nomsId}`)
}

// If all awaiting approval are PADA's then redirect to the submit screen (skip approve step)
if (!adasToReview.awaitingApproval.some(a => a.charges.some(c => c.status !== 'PROSPECTIVE'))) {
return res.redirect(`/${nomsId}/additional-days/review-and-submit`)
}

return res.render('pages/adjustments/additional-days/review-and-approve', {
model: {
prisonerDetail,
Expand Down
15 changes: 9 additions & 6 deletions server/views/macros/adaTable.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ emptyTitle: optional, displayed if table is empty
checkboxes: optional, defaults to false, does table have checkboxes
hideStatuses: optional, defaults to false , should the status of the ada be displayed
totalText: optional, defaults to 'Total' , the text displayed next to the total.
showTotalPerDateCharged: optional, defaults to false, should the total be shown per charge date
#}
{% macro adaTable(params) %}
{% if params.adas | length %}
Expand Down Expand Up @@ -87,12 +88,14 @@ totalText: optional, defaults to 'Total' , the text displayed next to the total
<td class="govuk-table__cell govuk-!-text-align-right">{{ charge.days }}</td>
</tr>
{% endfor %}
<tfoot>
<tr class="govuk-table__row">
<th class="govuk-table__cell govuk-!-text-align-left" scope="row" colspan="3">Total</th>
<td class="govuk-table__cell govuk-!-text-align-right">{{ ada.total }}</td>
</tr>
</tfoot>
{% if params.showTotalPerDateCharged %}
<tfoot>
<tr class="govuk-table__row">
<th class="govuk-table__cell govuk-!-text-align-left" scope="row" colspan="3">Total</th>
<td class="govuk-table__cell govuk-!-text-align-right">{{ ada.total }}</td>
</tr>
</tfoot>
{% endif %}
</table>
</td>
</tr>
Expand Down
3 changes: 2 additions & 1 deletion server/views/pages/adjustments/additional-days/view.njk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
adas: model.adas.awarded,
total: model.adas.totalAwarded,
hideStatuses: true,
totalText: 'Total ADAs taken into calculation'
totalText: 'Total ADAs taken into calculation',
showTotalPerDateCharged: true,
}) }}

</div>
Expand Down