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

Amend no returns message in view licence Returns tab #1087

Merged
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0e9117b
View Licence Returns no return messages
jonathangoulding Jun 11, 2024
b2535dc
feat: add fetch for returns requirements check
jonathangoulding Jun 11, 2024
bb96e66
chore: pre pr check
jonathangoulding Jun 11, 2024
f523b2b
chore: pre pr check
jonathangoulding Jun 11, 2024
f64f88e
chore: pre pr check
jonathangoulding Jun 11, 2024
219424d
chore: pre pr check
jonathangoulding Jun 11, 2024
6672c29
fix: old style test
jonathangoulding Jun 11, 2024
01596a9
chore: pre pr check
jonathangoulding Jun 11, 2024
552c5ed
chore: pre pr check
jonathangoulding Jun 11, 2024
120586e
Merge branch 'main' into feature-licence-returns-summary-no-returns-m…
jonathangoulding Jun 12, 2024
ddf7ea9
refactor: has requirements into the returns service
jonathangoulding Jun 12, 2024
6c51c5f
chore: rename to private method
jonathangoulding Jun 12, 2024
3fe3d75
chore: remove .only
jonathangoulding Jun 12, 2024
a5ba5ad
chore: remove .only
jonathangoulding Jun 12, 2024
ace05de
refactor: error message implementation
jonathangoulding Jun 12, 2024
ed310ed
refactor: rename to DetermineLicenceHasReturnVersionsService
jonathangoulding Jun 12, 2024
b1d5eec
Merge branch 'main' into feature-licence-returns-summary-no-returns-m…
jonathangoulding Jun 12, 2024
26d04aa
Merge branch 'main' into feature-licence-returns-summary-no-returns-m…
jonathangoulding Jun 12, 2024
d774fb2
Update app/views/licences/tabs/returns.njk
jonathangoulding Jun 12, 2024
705fd1c
Update app/views/licences/tabs/returns.njk
jonathangoulding Jun 12, 2024
e46c807
Update app/services/licences/determine-licence-has-return-versions.se…
jonathangoulding Jun 12, 2024
f5b2ec3
Update app/services/licences/determine-licence-has-return-versions.se…
jonathangoulding Jun 12, 2024
d6e80c2
Update app/services/licences/determine-licence-has-return-versions.se…
jonathangoulding Jun 12, 2024
c639d27
Update app/views/licences/tabs/returns.njk
jonathangoulding Jun 12, 2024
6eef66e
fix: pr isssues
jonathangoulding Jun 12, 2024
8b158a3
Merge remote-tracking branch 'origin/feature-licence-returns-summary-…
jonathangoulding Jun 12, 2024
30bab8d
Update test/services/licences/determine-licence-has-return-versions.s…
jonathangoulding Jun 12, 2024
1b1f240
Merge branch 'main' into feature-licence-returns-summary-no-returns-m…
jonathangoulding Jun 12, 2024
d835aff
Merge branch 'main' into feature-licence-returns-summary-no-returns-m…
jonathangoulding Jun 13, 2024
245e718
Merge branch 'main' into feature-licence-returns-summary-no-returns-m…
jonathangoulding Jun 13, 2024
ee066a7
Merge branch 'main' into feature-licence-returns-summary-no-returns-m…
jonathangoulding Jun 13, 2024
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
26 changes: 22 additions & 4 deletions app/presenters/licences/view-licence-returns.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
* @module ViewLicenceReturnsPresenter
*/

const { formatLongDate } = require('../base.presenter')
const { formatLongDate } = require('../base.presenter.js')

/**
* Formats common data for the `/licences/{id}/*` view licence pages
*
* @param {module:ReturnLogModel[]} returnsData - The session for the return requirement journey
* @param {boolean} hasRequirements - If the licence has return versions then it has requirements
*
* @returns {Object} The data formatted for the view template
*/
function go (returnsData) {
const returns = _formatReturnToTableRow(returnsData.returns)
function go (returnsData, hasRequirements) {
const returns = _formatReturnToTableRow(returnsData)

const hasReturns = returns.length > 0

return {
activeTab: 'returns',
returns
returns,
noReturnsMessage: _noReturnsMessage(hasReturns, hasRequirements)
}
}

Expand Down Expand Up @@ -53,6 +59,18 @@ function _formatStatus (status) {
return 'NO STATUS'
}

function _noReturnsMessage (hasReturns, hasRequirements) {
if (!hasReturns && !hasRequirements) {
return 'No requirements for returns have been set up for this licence.'
}

if (hasRequirements && !hasReturns) {
return 'No returns for this licence.'
}

return null
}

module.exports = {
go
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

/**
* Determines if a licence has requirements
* @module DetermineLicenceHasReturnVersionsService
*/

const ReturnVersionModel = require('../../models/return-version.model.js')

/**
* Determines if a licence has requirements
*
* @param {string} licenceId - The UUID for the licence id to fetch
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
*
* @returns {Promise<Boolean>} the result of check if a licence has requirements for returns
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
*/
async function go (licenceId) {
const requirement = await _fetch(licenceId)

return !!requirement
}

async function _fetch (licenceId) {
return ReturnVersionModel.query()
.select([
'id'
])
.where('licenceId', licenceId)
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
.first()
}

module.exports = {
go
}
15 changes: 10 additions & 5 deletions app/services/licences/view-licence-returns.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
* @module ViewLicenceSummaryService
*/

const FetchLicenceReturnsService = require('./fetch-licence-returns.service')
const ViewLicenceService = require('./view-licence.service')
const ViewLicenceReturnsPresenter = require('../../presenters/licences/view-licence-returns.presenter')
const PaginatorPresenter = require('../../presenters/paginator.presenter')
const DetermineLicenceHasReturnVersionsService = require('./determine-licence-has-return-versions.service.js')
const FetchLicenceReturnsService = require('./fetch-licence-returns.service.js')
const PaginatorPresenter = require('../../presenters/paginator.presenter.js')
const ViewLicenceReturnsPresenter = require('../../presenters/licences/view-licence-returns.presenter.js')
const ViewLicenceService = require('./view-licence.service.js')

/**
* Orchestrates fetching and presenting the data needed for the licence summary page
*
* @param {string} licenceId - The UUID of the licence
* @param {Object} auth - The auth object taken from `request.auth` containing user details
* @param {Object} page - The current page for the pagination service
*
* @returns {Promise<Object>} an object representing the `pageData` needed by the licence summary template.
*/
async function go (licenceId, auth, page) {
const commonData = await ViewLicenceService.go(licenceId, auth)

const hasRequirements = await DetermineLicenceHasReturnVersionsService.go(licenceId)

const returnsData = await FetchLicenceReturnsService.go(licenceId, page)
const pageData = ViewLicenceReturnsPresenter.go(returnsData)
const pageData = ViewLicenceReturnsPresenter.go(returnsData.returns, hasRequirements)

const pagination = PaginatorPresenter.go(returnsData.pagination.total, Number(page), `/system/licences/${licenceId}/returns`)

Expand Down
2 changes: 1 addition & 1 deletion app/services/licences/view-licence.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const ViewLicencePresenter = require('../../presenters/licences/view-licence.pre
* Orchestrates fetching and presenting the data needed for the licence summary page
*
* @param {string} licenceId - The UUID of the licence
* @param {string} auth - Auth object
* @param {Object} auth - The auth object taken from `request.auth` containing user details
* @returns {Promise<Object>} an object representing the `pageData` needed by the licence summary template.
*/
async function go (licenceId, auth) {
Expand Down
78 changes: 49 additions & 29 deletions app/views/licences/tabs/returns.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,56 @@
{% endif %}
{% endmacro %}

<table class="govuk-table">
<h2 class="govuk-heading-l">Returns</h2>
{% if returns.length > 0 %}
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Return reference and dates</th>
<th scope="col" class="govuk-table__header">Purpose and description</th>
<th scope="col" class="govuk-table__header">Due date</th>
<th scope="col" class="govuk-table__header">Status</th>
</tr>
</thead>
<tbody class="govuk-table__body">
{% for return in returns %}
<tr class="govuk-table__row govuk-body-s">
<th class="govuk-table__cell">
<a href="/return/internal?returnId={{ return.id }}" class="govuk-link">{{ return.reference }} </a>
<p class="govuk-body-s"> {{ return.dates }}</p>
</th>
<td class="govuk-table__cell">{{ return.purpose }} <p class="govuk-body-s"> {{ return.description }}</p></td>
<td class="govuk-table__cell">{{ return.dueDate }}</td>
<td class="govuk-table__cell">{{ formatStatus(return.status) }}</td>
</tr>
{% endfor %}
</tbody>
{% else %}
<p>No returns found</p>
{% endif %}
</table>
<h2 class="govuk-heading-l">Returns</h2>

{% if noReturnsMessage %}
<p> {{ noReturnsMessage }} </p>
{% else %}

{% macro referneceColum(return) %}
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
<a href="/return/internal?returnId={{ return.id }}" class="govuk-link">{{ return.reference }} </a>
<p class="govuk-body-s"> {{ return.dates }}</p>
{% endmacro %}

{% set returnRows = [] %}

{% for returnItem in returns %}
{% set returnRows = (returnRows.push([
{
html: referneceColum(returnItem)
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
},
{
html: returnItem.purpose + "<p class=\"govuk-body-s\">" + returnItem.description + "</p>"
},
{
text: returnItem.dueDate
},
{
html: formatStatus(returnItem.status)
}
]), returnRows) %}
{% endfor %}

{{ govukTable({
head: [
{
text: 'Return reference and dates'
},
{
text: 'Purpose and description'
},
{
text: 'Due date'
},
{
text: 'Status'
}
],
rows: returnRows
}) }}
{% endif %}

{% if returns and pagination.numberOfPages > 1 %}
{% if hasReturns and pagination.numberOfPages > 1 %}
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
{{ govukPagination(pagination.component) }}
{% endif %}

27 changes: 13 additions & 14 deletions test/controllers/licences.controller.test.js
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,15 @@ describe('Licences controller', () => {
}
})

describe('when a request is valid and has returns', () => {
describe('when a request is valid and has returns and the licence has requirements', () => {
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(async () => {
Sinon.stub(ViewLicenceReturnsService, 'go').resolves(_viewLicenceReturns())
Sinon.stub(ViewLicenceReturnsService, 'go').resolves({
activeTab: 'returns',
returns: [
{ id: 'returns-id' }
],
noReturnsMessage: null
})
})

it('returns the page successfully', async () => {
Expand All @@ -421,21 +427,21 @@ describe('Licences controller', () => {
})
})

describe('when a request is valid and has NO returns', () => {
describe('when a request is valid and has requirements but NO returns', () => {
jonathangoulding marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(async () => {
Sinon.stub(ViewLicenceReturnsService, 'go').resolves({
activeTab: 'returns',
returns: []
returns: [],
noReturnsMessage: 'No returns for this licence.'
})
})

it('returns the page successfully', async () => {
it('returns the page successfully with the message \'No returns for this licence.\'', async () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Returns')
// Check the table titles
expect(response.payload).to.contain('No returns found')
expect(response.payload).to.contain('No returns for this licence.')
})
})
})
Expand Down Expand Up @@ -474,13 +480,6 @@ function _viewLicenceContactDetails () {
}
}

function _viewLicenceReturns () {
return {
activeTab: 'returns',
returns: [{ id: 'returns-id' }]
}
}

function _viewLicenceSummary () {
return {
id: '7861814c-ca19-43f2-be11-3c612f0d744b',
Expand Down
Loading
Loading