Skip to content
Draft
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
9 changes: 9 additions & 0 deletions app/presenters/licence-versions/view.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function go(licenceVersionData, auth) {
},
changeType: licenceVersion.administrative ? 'no licence issued' : 'licence issued',
errorInDataEmail: _errorInDataEmail(billingAndDataRole),
licenceDetails: _licenceDetails(licenceVersion, licence),
notes: _notes(licenceVersion, billingAndDataRole),
pageTitle: `Licence version starting ${formatLongDate(licenceVersion.startDate)}`,
pageTitleCaption: `Licence ${licence.licenceRef}`,
Expand All @@ -46,6 +47,14 @@ function _errorInDataEmail(billingAndDataRole) {
return '[email protected]'
}

function _licenceDetails(licenceVersion, licence) {
return {
endDate: formatLongDate(licenceVersion.endDate),
licenceHolder: licence.$licenceHolder(),
startDate: formatLongDate(licenceVersion.startDate)
}
}

function _notes(licenceVersion, billingAndDataRole) {
if (!billingAndDataRole) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ async function _fetch(licenceVersionId) {
.select([
'id',
'startDate',
'endDate',
raw(
'(SELECT true FROM public.licence_versions lv2 WHERE lv2.licence_id = licence_versions.licence_id AND lv2.issue = licence_versions.issue AND lv2."increment" = (licence_versions."increment" - 1))'
).as('administrative')
])
.withGraphFetched('licence')
.modifyGraph('licence', (builder) => {
builder.select(['id', 'licenceRef'])
builder.modify('licenceHolder')
})
.modify('history')
}
Expand Down
43 changes: 43 additions & 0 deletions app/views/licence-versions/view.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

{% from "macros/licence-version-change-type-tag.njk" import changeTypeTag as licenceVersionChangeTypeTag %}

{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %}

{% block pageContent %}

Expand All @@ -29,4 +30,46 @@
{{ govukPagination(pagination) }}
{% endif %}


<hr class="govuk-section-break govuk-section-break--l govuk-section-break--visible govuk-!-margin-top-4">

<ul class="govuk-list govuk-!-margin-bottom-6">
<li>
<a class="govuk-link" href="#licence-details">Licence details</a>
</li>
</ul>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full" id="licence-details">
<h2 class="govuk-heading-m govuk-!-margin-top-3">
Licence details
</h2>
{{ govukSummaryList({
card: {
title: {
text: licenceDetails.licenceHolder
}
},
rows: [
{
key: {
text: "Licence version start date"
},
value: {
text: licenceDetails.startDate
}
},
{
key: {
text: "Licence version end date"
},
value: {
text: licenceDetails.endDate
}
}
]
}) }}

</div>
</div>
{% endblock %}
37 changes: 37 additions & 0 deletions test/presenters/licence-versions/view.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ describe('Licence Versions - View presenter', () => {
},
changeType: 'licence issued',
errorInDataEmail: '[email protected]',
licenceDetails: {
endDate: null,
licenceHolder: null,
startDate: '1 January 2022'
},
notes: null,
pageTitle: 'Licence version starting 1 January 2022',
pageTitleCaption: `Licence ${licence.licenceRef}`,
Expand Down Expand Up @@ -119,6 +124,38 @@ describe('Licence Versions - View presenter', () => {
})
})

describe('the "licenceDetails" property', () => {
it('returns the licence details', () => {
const result = ViewPresenter.go(licenceVersionData, auth)

expect(result.licenceDetails).to.equal({ endDate: null, licenceHolder: null, startDate: '1 January 2022' })
})

describe('the "licenceHolder" property', () => {
describe('when there is not a "licenceHolder"', () => {
it('returns null', () => {
const result = ViewPresenter.go(licenceVersionData, auth)

expect(result.licenceDetails.licenceHolder).to.be.null()
})
})

describe('when there is a "licenceHolder"', () => {
beforeEach(() => {
licenceVersionData.licenceVersion.licence.licenceDocument = {
licenceDocumentRoles: [{ company: { name: 'ACME' } }]
}
})

it('returns the licence holder', () => {
const result = ViewPresenter.go(licenceVersionData, auth)

expect(result.licenceDetails.licenceHolder).to.equal('ACME')
})
})
})
})

describe('the "notes" property', () => {
describe('when the user does not have the "billing" role', () => {
it('returns null', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ describe('Licence Versions - Fetch licence version service', () => {
licenceVersion: {
administrative: null,
createdAt: licenceVersion.createdAt,
endDate: null,
id: licenceVersion.id,
licence: {
id: licence.id,
licenceRef: licence.licenceRef
licenceRef: licence.licenceRef,
licenceDocument: null
},
modLogs: [],
startDate: licenceVersion.startDate
Expand Down
5 changes: 5 additions & 0 deletions test/services/licence-versions/view.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ describe('Licence Versions - View service', () => {
},
changeType: 'licence issued',
errorInDataEmail: '[email protected]',
licenceDetails: {
endDate: null,
licenceHolder: null,
startDate: '1 January 2022'
},
notes: null,
pageTitle: 'Licence version starting 1 January 2022',
pageTitleCaption: `Licence ${licence.licenceRef}`,
Expand Down
Loading