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

Manage 2PT Status on Licence review page #918

Merged
merged 11 commits into from
Apr 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ const { formatLongDate } = require('../../base.presenter.js')
*
* @param {module:BillRunModel} billRun the data from the bill run
* @param {module:ReviewLicenceModel} licence the data from review licence
* @param {String} licenceStatus will contain the string 'ready' or 'review' if the licence review status button has
* been clicked, otherwise it will be null. It is used to determine the message displayed by the 'Licence updated'
* banner, if any
* @param {String} markProgress will contain the string 'mark' or 'unmark' if the mark/unmark progress button has been
* clicked, otherwise it will be null. It is passed back to the view to determine if the 'Licence updated' banner should
* be displayed
* clicked, otherwise it will be null. It is used to determine the message displayed by the 'Licence updated'
* banner, if any
*
* @returns {Object} the prepared bill run and licence data to be passed to the review licence page
*/
function go (billRun, licence, markProgress) {
function go (billRun, licence, licenceStatus, markProgress) {
return {
billRunId: billRun.id,
region: billRun.region.displayName,
Expand All @@ -31,7 +34,7 @@ function go (billRun, licence, markProgress) {
progress: licence[0].progress
},
elementsInReview: licence[0].hasReviewStatus,
licenceUpdated: _licenceUpdated(markProgress),
licenceUpdatedMessage: _licenceUpdatedMessage(licenceStatus, markProgress),
matchedReturns: _matchedReturns(licence[0].reviewReturns),
unmatchedReturns: _unmatchedReturns(licence[0].reviewReturns),
chargeData: _prepareChargeData(licence, billRun)
Expand Down Expand Up @@ -140,14 +143,17 @@ function _financialYear (financialYearEnding) {
return `${startYear} to ${endYear}`
}

function _licenceUpdated (markProgress) {
switch (markProgress) {
case 'mark':
return 'This licence has been marked.'
case 'unmark':
return 'The progress mark for this licence has been removed.'
default:
return null
function _licenceUpdatedMessage (licenceStatus, markProgress) {
if (licenceStatus === 'ready') {
return 'Licence changed to ready.'
} else if (licenceStatus === 'review') {
return 'Licence changed to review.'
} else if (markProgress === 'mark') {
return 'This licence has been marked.'
} else if (markProgress === 'unmark') {
return 'The progress mark for this licence has been removed.'
} else {
return null
}
}

Expand Down
24 changes: 21 additions & 3 deletions app/services/bill-runs/two-part-tariff/review-licence.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,30 @@ const ReviewLicencePresenter = require('../../../presenters/bill-runs/two-part-t
* licence, bill run, matched and unmatched returns and the licence charge data
*/
async function go (billRunId, licenceId, payload) {
const licenceStatus = payload?.licenceStatus
const markProgress = payload?.marKProgress

if (markProgress === 'mark' || markProgress === 'unmark') {
await _updateProgress(billRunId, licenceId, markProgress)
if (payload) {
await _processPayload(billRunId, licenceId, licenceStatus, markProgress)
}

const { billRun, licence } = await FetchReviewLicenceResultsService.go(billRunId, licenceId)

const pageData = ReviewLicencePresenter.go(billRun, licence, markProgress)
const pageData = ReviewLicencePresenter.go(billRun, licence, licenceStatus, markProgress)

return pageData
}

async function _processPayload (billRunId, licenceId, licenceStatus, markProgress) {
if (licenceStatus === 'ready' || licenceStatus === 'review') {
await _updateStatus(billRunId, licenceId, licenceStatus)
}

if (markProgress === 'mark' || markProgress === 'unmark') {
await _updateProgress(billRunId, licenceId, markProgress)
}
}

async function _updateProgress (billRunId, licenceId, marKProgress) {
const progress = marKProgress === 'mark'

Expand All @@ -43,6 +54,13 @@ async function _updateProgress (billRunId, licenceId, marKProgress) {
.andWhere('licenceId', licenceId)
}

async function _updateStatus (billRunId, licenceId, licenceStatus) {
await ReviewLicenceModel.query()
.patch({ status: licenceStatus })
.where('billRunId', billRunId)
.andWhere('licenceId', licenceId)
}

module.exports = {
go
}
25 changes: 23 additions & 2 deletions app/views/bill-runs/review-licence.njk
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

{% block content %}
{# Licence updated banner #}
{% if licenceUpdated %}
{% if licenceUpdatedMessage %}
{{ govukNotificationBanner({
titleText: 'Licence updated',
text: licenceUpdated
text: licenceUpdatedMessage
}) }}
{% endif %}

Expand Down Expand Up @@ -60,6 +60,17 @@
}) }}
{% endif %}

{# Change status #}
{% if licence.status === 'ready' %}
{% set statusButtonText = 'Put licence into Review' %}
{% set statusButtonValue = 'review' %}
{% set statusButtonClass = "govuk-button--secondary" %}
{% else %}
{% set statusButtonText = 'Confirm licence is ready' %}
{% set statusButtonValue = 'ready' %}
{% set statusButtonClass = "govuk-button--primary" %}
{% endif %}

{# Mark progress #}
{% if licence.progress %}
{% set progressButtonText = 'Remove progress mark' %}
Expand All @@ -70,13 +81,23 @@
{% endif %}

<form method="post">
<div class="govuk-button-group">
{{ govukButton({
text: statusButtonText,
classes: statusButtonClass,
preventDoubleClick: true,
name: "licenceStatus",
value: statusButtonValue
}) }}

{{ govukButton({
text: progressButtonText,
classes: "govuk-button--secondary",
preventDoubleClick: true,
name: "marKProgress",
value: progressButtonValue
}) }}
</div>
</form>

{# Charge Periods #}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ const ReviewLicencePresenter = require('../../../../app/presenters/bill-runs/two
describe('Review Licence presenter', () => {
let billRun
let licence
let licenceStatus
let markProgress

describe('when there is data to be presented for the review licence page', () => {
beforeEach(() => {
billRun = _billRun()
licence = _licenceData()
licenceStatus = undefined
markProgress = undefined
})

it('correctly presents the data', async () => {
const result = ReviewLicencePresenter.go(billRun, licence, markProgress)
const result = ReviewLicencePresenter.go(billRun, licence, licenceStatus, markProgress)

expect(result).to.equal({
billRunId: '6620135b-0ecf-4fd4-924e-371f950c0526',
Expand All @@ -35,7 +37,7 @@ describe('Review Licence presenter', () => {
status: 'ready',
licenceHolder: 'Licence Holder Ltd'
},
licenceUpdated: null,
licenceUpdatedMessage: null,
elementsInReview: false,
matchedReturns: [
{
Expand Down Expand Up @@ -186,31 +188,63 @@ describe('Review Licence presenter', () => {
})
})

describe('when there is data to be presented and the user has clicked the "Confirm licence is ready" button', () => {
beforeEach(() => {
billRun = _billRun()
licence = _licenceData()
licenceStatus = 'ready'
markProgress = undefined
})

it('correctly returns the text for the "Licence updated" notification banner', async () => {
const result = ReviewLicencePresenter.go(billRun, licence, licenceStatus, markProgress)

expect(result.licenceUpdatedMessage).to.equal('Licence changed to ready.')
})
})

describe('when there is data to be presented and the user has clicked the "Put licence into Review" button', () => {
beforeEach(() => {
billRun = _billRun()
licence = _licenceData()
licenceStatus = 'review'
markProgress = undefined
})

it('correctly returns the text for the "Licence updated" notification banner', async () => {
const result = ReviewLicencePresenter.go(billRun, licence, licenceStatus, markProgress)

expect(result.licenceUpdatedMessage).to.equal('Licence changed to review.')
})
})

describe('when there is data to be presented and the user has clicked the "Mark progress" button', () => {
beforeEach(() => {
billRun = _billRun()
licence = _licenceData()
licenceStatus = undefined
markProgress = 'mark'
})

it('correctly returns the text for the "Licence updated" notification banner', async () => {
const result = ReviewLicencePresenter.go(billRun, licence, markProgress)
const result = ReviewLicencePresenter.go(billRun, licence, licenceStatus, markProgress)

expect(result.licenceUpdated).to.equal('This licence has been marked.')
expect(result.licenceUpdatedMessage).to.equal('This licence has been marked.')
})
})

describe('when there is data to be presented and the user has clicked the "Remove progress mark" button', () => {
beforeEach(() => {
billRun = _billRun()
licence = _licenceData()
licenceStatus = undefined
markProgress = 'unmark'
})

it('correctly returns the text for the "Licence updated" notification banner', async () => {
const result = ReviewLicencePresenter.go(billRun, licence, markProgress)
const result = ReviewLicencePresenter.go(billRun, licence, licenceStatus, markProgress)

expect(result.licenceUpdated).to.equal('The progress mark for this licence has been removed.')
expect(result.licenceUpdatedMessage).to.equal('The progress mark for this licence has been removed.')
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,55 @@ describe('Review Licence Service', () => {
})
})

describe('when there is data to process following the user clicking the "Mark progress" button', () => {
describe('when there is data to process after the user clicking the "Confirm licence is ready" button', () => {
const payload = { licenceStatus: 'ready' }
let billRunId
let licenceId

beforeEach(async () => {
const reviewLicence = await ReviewLicenceHelper.add({ status: 'review' })

billRunId = reviewLicence.billRunId
licenceId = reviewLicence.licenceId
})

it('will set `status` to `ready` in the database and return the page data', async () => {
const result = await ReviewLicenceService.go(billRunId, licenceId, payload)
const reviewLicenceQuery = await ReviewLicenceModel.query()
.where('billRunId', billRunId)
.andWhere('licenceId', licenceId)
.first()

expect(reviewLicenceQuery.status).to.equal('ready')
expect(result).to.equal('page data')
})
})

describe('when there is data to process after the user clicking the "Put licence into Review" button', () => {
const payload = { licenceStatus: 'review' }
let billRunId
let licenceId

beforeEach(async () => {
const reviewLicence = await ReviewLicenceHelper.add({ status: 'ready' })

billRunId = reviewLicence.billRunId
licenceId = reviewLicence.licenceId
})

it('will set `status` to `review` in the database and return the page data', async () => {
const result = await ReviewLicenceService.go(billRunId, licenceId, payload)
const reviewLicenceQuery = await ReviewLicenceModel.query()
.where('billRunId', billRunId)
.andWhere('licenceId', licenceId)
.first()

expect(reviewLicenceQuery.status).to.equal('review')
expect(result).to.equal('page data')
})
})

describe('when there is data to process after the user clicking the "Mark progress" button', () => {
const payload = { marKProgress: 'mark' }
let billRunId
let licenceId
Expand All @@ -71,7 +119,7 @@ describe('Review Licence Service', () => {
})
})

describe('when there is data to process following the user clicking the "Remove progress mark" button', () => {
describe('when there is data to process after the user clicking the "Remove progress mark" button', () => {
const payload = { marKProgress: 'unmark' }
let billRunId
let licenceId
Expand Down
Loading