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

Fix workflow start date in view licence set up tab #1176

Merged
merged 4 commits into from
Jul 9, 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
34 changes: 9 additions & 25 deletions app/presenters/licences/set-up.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function _chargeVersions (chargeVersions) {
id: chargeVersion.id,
startDate: formatLongDate(chargeVersion.startDate),
endDate: chargeVersion.endDate ? formatLongDate(chargeVersion.endDate) : '',
status: _status(chargeVersion.status),
status: chargeVersion.status,
reason: chargeVersion.changeReason?.description,
action: [
{
Expand Down Expand Up @@ -182,7 +182,7 @@ function _returnVersions (returnVersions = [{}]) {
endDate: returnVersion.endDate ? formatLongDate(returnVersion.endDate) : '',
reason: returnVersion.reason ? returnRequirementReasons[returnVersion.reason] : '',
startDate: formatLongDate(returnVersion.startDate),
status: _status(returnVersion.status)
status: returnVersion.status
}
})
}
Expand All @@ -198,22 +198,6 @@ function _returnVersionsLinks (commonData, enableRequirementsForReturns) {
return {}
}

function _status (status) {
const statuses = {
current: 'approved',
draft: 'draft',
approved: 'approved',
replaced: 'replaced',
superseded: 'replaced',
invalid: 'invalid',
review: 'review',
changes_requested: 'change request',
to_setup: 'to set up'
}

return statuses[status]
}

function _workflows (workflows, auth) {
return workflows.map((workflow) => {
return {
Expand All @@ -222,7 +206,7 @@ function _workflows (workflows, auth) {
id: workflow.id,
reason: workflow.data.chargeVersion?.changeReason?.description,
startDate: _workflowStartDate(workflow),
status: _status(workflow.status)
status: workflow.status
}
})
}
Expand Down Expand Up @@ -262,14 +246,14 @@ function _workflowActionReviewer (workflow) {
}

function _workflowStartDate (workflow) {
if (workflow.status === 'review') {
// Stored as JSON the date is returned as a string. So, we need to convert it to a date type first
const startDate = new Date(workflow.data.chargeVersion.dateRange.startDate)

return formatLongDate(startDate)
if (workflow.status === 'to_setup') {
return ''
}

return ''
// Stored as JSON the date is returned as a string. So, we need to convert it to a date type first
const startDate = new Date(workflow.data.chargeVersion.dateRange.startDate)

return formatLongDate(startDate)
}

module.exports = {
Expand Down
11 changes: 1 addition & 10 deletions app/presenters/return-requirements/view.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function go (requirementsForReturns) {
reason: returnRequirementReasons[reason] || '',
requirements: _requirements(returnRequirements),
startDate: formatLongDate(startDate),
status: _status(status),
status,
createdDate: formatLongDate(createdAt),
createdBy: user ? user.username : 'Migrated from NALD'
}
Expand Down Expand Up @@ -129,15 +129,6 @@ function _requirements (requirements) {
})
}

function _status (status) {
const statuses = {
current: 'approved',
superseded: 'replaced'
}

return statuses[status]
}

module.exports = {
go
}
8 changes: 5 additions & 3 deletions app/views/licences/tabs/set-up.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% from "govuk/components/button/macro.njk" import govukButton %}
{% from "govuk/components/table/macro.njk" import govukTable %}
{% from "macros/charge-version-status-tag.njk" import statusTag %}

{% from "macros/charge-version-status-tag.njk" import statusTag as chargeVersionStatusTag %}
{% from "macros/return-version-status-tag.njk" import statusTag as returnVersionStatusTag %}

{% macro createLink(data) %}
{% for linkItem in data.action %}
Expand Down Expand Up @@ -30,7 +32,7 @@
text: returnsRequirement.reason
},
{
html: statusTag(returnsRequirement.status)
html: returnVersionStatusTag(returnsRequirement.status, true)
},
{
html: createLink(returnsRequirement)
Expand Down Expand Up @@ -99,7 +101,7 @@
text: chargeVersion.reason
},
{
html: statusTag(chargeVersion.status)
html: chargeVersionStatusTag(chargeVersion.status, true)
},
{
html: createLink(chargeVersion)
Expand Down
45 changes: 27 additions & 18 deletions app/views/macros/charge-version-status-tag.njk
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
{% from "govuk/components/tag/macro.njk" import govukTag %}

{% macro statusTag(status) %}
{% if status === 'approved' %}
{% set classes = "govuk-tag--green" %}
{% elif status === 'replaced' %}
{% set classes = "govuk-tag--grey" %}
{% elif status === 'superseded' %}
{% set classes = "govuk-tag--grey" %}
{% elif status === 'invalid' %}
{% set classes = "govuk-tag--red" %}
{% elif status === 'review' %}
{% set classes = "govuk-tag--orange" %}
{% elif status === 'change request' %}
{% set classes = "govuk-tag--blue" %}
{% elif status === 'to set up' %}
{% set classes = "govuk-tag--blue" %}
{% macro statusTag(status, inline=false) %}
{# Default the text to the status as that covers most tags #}
{% set text = status %}

{% if status === 'current' %}
{% set color = "govuk-tag--green" %}
{% set text = 'approved' %}
{% elif status === 'superseded' %}
{% set color = "govuk-tag--grey" %}
{% set text = 'replaced' %}
{% elif status === 'review' %}
{% set color = "govuk-tag--orange" %}
{% elif status === 'changes_requested' %}
{% set color = "govuk-tag--blue" %}
{% set text = 'change request' %}
{% elif status === 'to_setup' %}
{% set color = "govuk-tag--blue" %}
{% set text = 'to set up' %}
{% else %}
{% set color = "govuk-tag--blue" %}
{% endif %}

{% if inline %}
{% set fontSize = "" %}
{% else %}
{% set classes = "" %}
{% set fontSize = "govuk-!-font-size-27" %}
{% endif %}

{{ govukTag({
text: status,
classes: classes
text: text,
classes: color + ' ' + fontSize
}) }}
{% endmacro %}
27 changes: 27 additions & 0 deletions app/views/macros/return-version-status-tag.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% from "govuk/components/tag/macro.njk" import govukTag %}

{% macro statusTag(status, inline=false) %}
{# Default the text to the status as that covers most tags #}
{% set text = status %}

{% if status === 'current' %}
{% set color = "govuk-tag--green" %}
{% set text = 'approved' %}
{% elif status === 'superseded' %}
{% set color = "govuk-tag--grey" %}
{% set text = 'replaced' %}
{% else %}
{% set color = "govuk-tag--blue" %}
{% endif %}

{% if inline %}
{% set fontSize = "" %}
{% else %}
{% set fontSize = "govuk-!-font-size-27" %}
{% endif %}

{{ govukTag({
text: text,
classes: color + ' ' + fontSize
}) }}
{% endmacro %}
3 changes: 2 additions & 1 deletion app/views/return-requirements/view.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% extends 'layout.njk' %}
{% from "govuk/components/back-link/macro.njk" import govukBackLink %}
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %}
{% from "macros/charge-version-status-tag.njk" import statusTag %}

{% from "macros/return-version-status-tag.njk" import statusTag %}

{% macro newLine(array) %}
{% for item in array %}
Expand Down
58 changes: 51 additions & 7 deletions test/presenters/licences/set-up.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ describe('Licences - Set Up presenter', () => {
id: '0d514aa4-1550-46b1-8195-878957f2a5f8',
startDate: '1 January 2020',
endDate: '',
status: 'approved',
status: 'current',
reason: 'Major change'
}
])
Expand Down Expand Up @@ -373,7 +373,7 @@ describe('Licences - Set Up presenter', () => {
id: '0d514aa4-1550-46b1-8195-878957f2a5f8',
startDate: '1 January 2020',
endDate: '',
status: 'approved',
status: 'current',
reason: 'Major change'
}])
})
Expand All @@ -396,7 +396,7 @@ describe('Licences - Set Up presenter', () => {
id: '0d514aa4-1550-46b1-8195-878957f2a5f8',
startDate: '1 January 2020',
endDate: '31 March 2024',
status: 'approved',
status: 'current',
reason: 'Major change'
}])
})
Expand Down Expand Up @@ -451,6 +451,50 @@ describe('Licences - Set Up presenter', () => {
})
})

describe('that have a status of "changes_requested"', () => {
beforeEach(() => {
workflows = [{ ...workflow }]
workflows[0].status = 'changes_requested'
})

describe('and the user is permitted to review workflow records', () => {
beforeEach(() => {
auth.credentials.scope = ['billing', 'charge_version_workflow_reviewer']
})

it('correctly presents the data and workflow actions', () => {
const result = SetUpPresenter.go(chargeVersions, workflows, agreements, returnVersions, auth, commonData)

expect(result.chargeInformation).to.equal([{
action: [{
link: '/licences/f91bf145-ce8e-481c-a842-4da90348062b/charge-information/f547f465-0a62-45ff-9909-38825f05e0c4/review',
text: 'Review'
}],
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
startDate: '1 April 2022',
endDate: '',
status: 'changes_requested',
reason: 'changed something'
}])
})
})

describe('and the user is not permitted to review workflow records', () => {
it('correctly presents the data and workflow actions', () => {
const result = SetUpPresenter.go(chargeVersions, workflows, agreements, returnVersions, auth, commonData)

expect(result.chargeInformation).to.equal([{
action: [],
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
startDate: '1 April 2022',
endDate: '',
status: 'changes_requested',
reason: 'changed something'
}])
})
})
})

describe('that have a status of "to_setup"', () => {
beforeEach(() => {
workflows = [{ ...workflow }]
Expand All @@ -473,7 +517,7 @@ describe('Licences - Set Up presenter', () => {
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
startDate: '',
endDate: '',
status: 'to set up',
status: 'to_setup',
reason: 'changed something'
}])
})
Expand All @@ -492,7 +536,7 @@ describe('Licences - Set Up presenter', () => {
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
startDate: '',
endDate: '',
status: 'to set up',
status: 'to_setup',
reason: 'changed something'
}])
})
Expand All @@ -519,7 +563,7 @@ describe('Licences - Set Up presenter', () => {
endDate: '',
reason: 'Change to special agreement',
startDate: '1 January 2020',
status: 'approved'
status: 'current'
}
])
})
Expand All @@ -543,7 +587,7 @@ describe('Licences - Set Up presenter', () => {
endDate: '',
reason: '',
startDate: '1 January 2020',
status: 'approved'
status: 'current'
}
])
})
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/return-requirements/view.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('Return Requirements - View presenter', () => {
}
],
startDate: '21 April 2023',
status: 'approved'
status: 'current'
})
})

Expand Down
4 changes: 2 additions & 2 deletions test/services/licences/view-licence-set-up.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('View Licence Set Up service', () => {
id: 'c0601335-b6ad-4651-b54b-c586f8d22ac3',
reason: 'Missing thing',
startDate: '1 January 2020',
status: 'approved'
status: 'current'
}
],
licenceId: testId,
Expand All @@ -153,7 +153,7 @@ describe('View Licence Set Up service', () => {
endDate: '1 February 2025',
reason: 'Change to special agreement',
startDate: '1 January 2025',
status: 'approved'
status: 'current'
}
]
})
Expand Down
2 changes: 1 addition & 1 deletion test/services/return-requirements/view.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Return Requirements - View service', () => {
}
],
startDate: '1 April 2022',
status: 'approved'
status: 'current'
})
})
})
Expand Down
Loading