Skip to content

Commit

Permalink
Update how presenter determines status
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruikshanks committed Jun 16, 2024
1 parent a0b34b5 commit 338840e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
33 changes: 20 additions & 13 deletions app/presenters/licences/view-licence-returns.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,36 @@ function _formatPurpose (purpose) {
}

function _formatReturnToTableRow (returns) {
return returns.map((r) => {
return returns.map((returnLog) => {
return {
dates: `${formatLongDate(new Date(r.startDate))} to ${formatLongDate(new Date(r.endDate))}`,
description: r.metadata.description,
dueDate: formatLongDate(new Date(r.dueDate)),
id: r.id,
purpose: _formatPurpose(r.metadata.purposes),
reference: r.returnReference,
status: _formatStatus(r.status)
dates: `${formatLongDate(new Date(returnLog.startDate))} to ${formatLongDate(new Date(returnLog.endDate))}`,
description: returnLog.metadata.description,
dueDate: formatLongDate(new Date(returnLog.dueDate)),
id: returnLog.id,
purpose: _formatPurpose(returnLog.metadata.purposes),
reference: returnLog.returnReference,
status: _formatStatus(returnLog)
}
})
}

function _formatStatus (status) {
function _formatStatus (returnLog) {
const { status, dueDate } = returnLog

// If the return is completed we are required to display it as 'complete'. This also takes priority over the other
// statues
if (status === 'completed') {
return 'COMPLETE'
return 'complete'
}

if (status === 'due') {
return 'OVERDUE'
// Work out if the return is overdue (status is still 'due' and it is past the due date)
const today = new Date()
if (status === 'due' && dueDate < today) {
return 'overdue'
}

return 'NO STATUS'
// For all other cases we can just return the status and the return-status-tag macro will know how to display it
return status
}

function _noReturnsMessage (hasReturns, hasRequirements) {
Expand Down
10 changes: 5 additions & 5 deletions test/presenters/licences/view-licence-returns.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ describe('View Licence returns presenter', () => {

const returnItem = {
id: 'mock-id-1',
dueDate: '2012-11-28T00:00:00.000Z',
dueDate: new Date('2012-11-28'),
status: 'completed',
startDate: '2020/01/02',
endDate: '2020/02/01',
startDate: new Date('2020/01/02'),
endDate: new Date('2020/02/01'),
metadata: {
purposes: [
{
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('View Licence returns presenter', () => {
reference: '1068',
purpose: 'SPRAY IRRIGATION',
dueDate: '28 November 2012',
status: 'COMPLETE',
status: 'complete',
dates: '2 January 2020 to 1 February 2020',
description: 'empty description'
},
Expand All @@ -78,7 +78,7 @@ describe('View Licence returns presenter', () => {
reference: '1069',
purpose: 'SPRAY IRRIGATION',
dueDate: '28 November 2012',
status: 'OVERDUE',
status: 'overdue',
dates: '2 January 2020 to 1 February 2020',
description: 'empty description'
}
Expand Down

0 comments on commit 338840e

Please sign in to comment.