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 dates in view licence set up tab #1175

Merged
merged 10 commits into from
Jul 9, 2024
17 changes: 14 additions & 3 deletions app/presenters/licences/set-up.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function _chargeVersions (chargeVersions) {
return {
id: chargeVersion.id,
startDate: formatLongDate(chargeVersion.startDate),
endDate: chargeVersion.endDate ? formatLongDate(chargeVersion.endDate) : '-',
endDate: chargeVersion.endDate ? formatLongDate(chargeVersion.endDate) : '',
status: _status(chargeVersion.status),
reason: chargeVersion.changeReason?.description,
action: [
Expand Down Expand Up @@ -218,10 +218,10 @@ function _workflows (workflows, auth) {
return workflows.map((workflow) => {
return {
action: _workflowAction(workflow, auth),
endDate: '-',
endDate: '',
id: workflow.id,
reason: workflow.data.chargeVersion?.changeReason?.description,
startDate: workflow.createdAt ? formatLongDate(workflow.createdAt) : '-',
startDate: _workflowStartDate(workflow),
status: _status(workflow.status)
}
})
Expand Down Expand Up @@ -261,6 +261,17 @@ 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)
}

return ''
}

module.exports = {
go
}
57 changes: 33 additions & 24 deletions test/presenters/licences/set-up.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ describe('Licences - Set Up presenter', () => {
const chargeVersion = {
id: '0d514aa4-1550-46b1-8195-878957f2a5f8',
startDate: new Date('2020-01-01'),
endDate: new Date('2020-09-01'),
endDate: null,
status: 'current',
changeReason: { description: 'Major change' },
licenceId: 'f91bf145-ce8e-481c-a842-4da90348062b'
}

const returnVersion = {
id: '0312e5eb-67ae-44fb-922c-b1a0b81bc08d',
startDate: new Date('2025-01-01'),
endDate: new Date('2025-02-01'),
startDate: new Date('2020-01-01'),
endDate: null,
status: 'current',
reason: 'change-to-special-agreement'
}
Expand All @@ -44,7 +44,12 @@ describe('Licences - Set Up presenter', () => {
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
createdAt: new Date('2020-01-01'),
status: 'review',
data: { chargeVersion: { changeReason: { description: 'changed something' } } },
data: {
chargeVersion: {
changeReason: { description: 'changed something' },
dateRange: { startDate: '2022-04-01' }
}
},
licenceId: 'f91bf145-ce8e-481c-a842-4da90348062b'
}

Expand Down Expand Up @@ -294,6 +299,7 @@ describe('Licences - Set Up presenter', () => {
describe('when the licence is more than 6 years old and all the actions are available for an agreement', () => {
beforeEach(() => {
const sixYearsAndOneDayAgo = new Date()

sixYearsAndOneDayAgo.setDate(sixYearsAndOneDayAgo.getDate() - 1)
sixYearsAndOneDayAgo.setFullYear(sixYearsAndOneDayAgo.getFullYear() - 6)

Expand All @@ -317,15 +323,15 @@ describe('Licences - Set Up presenter', () => {
workflows = [{ ...workflow }]
})

it('groups both types of data into the \'chargeInformation\' property', () => {
it('groups both types of data into the "chargeInformation" property', () => {
const result = SetUpPresenter.go(chargeVersions, workflows, agreements, returnVersions, auth, commonData)

expect(result.chargeInformation).to.equal([
{
action: [],
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
startDate: '1 January 2020',
endDate: '-',
startDate: '1 April 2022',
endDate: '',
status: 'review',
reason: 'changed something'
},
Expand All @@ -336,7 +342,7 @@ describe('Licences - Set Up presenter', () => {
}],
id: '0d514aa4-1550-46b1-8195-878957f2a5f8',
startDate: '1 January 2020',
endDate: '1 September 2020',
endDate: '',
status: 'approved',
reason: 'Major change'
}
Expand Down Expand Up @@ -366,7 +372,7 @@ describe('Licences - Set Up presenter', () => {
}],
id: '0d514aa4-1550-46b1-8195-878957f2a5f8',
startDate: '1 January 2020',
endDate: '-',
endDate: '',
status: 'approved',
reason: 'Major change'
}])
Expand All @@ -376,6 +382,7 @@ describe('Licences - Set Up presenter', () => {
describe('where the end date is populated', () => {
beforeEach(() => {
chargeVersions = [{ ...chargeVersion }]
chargeVersions[0].endDate = new Date('2024-03-31')
})

it('correctly presents the data with the end date', () => {
Expand All @@ -388,7 +395,7 @@ describe('Licences - Set Up presenter', () => {
}],
id: '0d514aa4-1550-46b1-8195-878957f2a5f8',
startDate: '1 January 2020',
endDate: '1 September 2020',
endDate: '31 March 2024',
status: 'approved',
reason: 'Major change'
}])
Expand All @@ -401,7 +408,7 @@ describe('Licences - Set Up presenter', () => {
chargeVersions = []
})

describe('that have a status of \'review\'', () => {
describe('that have a status of "review"', () => {
beforeEach(() => {
workflows = [{ ...workflow }]
})
Expand All @@ -420,8 +427,8 @@ describe('Licences - Set Up presenter', () => {
text: 'Review'
}],
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
startDate: '1 January 2020',
endDate: '-',
startDate: '1 April 2022',
endDate: '',
status: 'review',
reason: 'changed something'
}])
Expand All @@ -435,16 +442,16 @@ describe('Licences - Set Up presenter', () => {
expect(result.chargeInformation).to.equal([{
action: [],
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
startDate: '1 January 2020',
endDate: '-',
startDate: '1 April 2022',
endDate: '',
status: 'review',
reason: 'changed something'
}])
})
})
})

describe('that have a status of \'to_setup\'', () => {
describe('that have a status of "to_setup"', () => {
beforeEach(() => {
workflows = [{ ...workflow }]
workflows[0].status = 'to_setup'
Expand All @@ -464,8 +471,8 @@ describe('Licences - Set Up presenter', () => {
text: 'Review'
}],
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
startDate: '1 January 2020',
endDate: '-',
startDate: '',
endDate: '',
status: 'to set up',
reason: 'changed something'
}])
Expand All @@ -483,8 +490,8 @@ describe('Licences - Set Up presenter', () => {
expect(result.chargeInformation).to.equal([{
action: [],
id: 'f547f465-0a62-45ff-9909-38825f05e0c4',
startDate: '1 January 2020',
endDate: '-',
startDate: '',
endDate: '',
status: 'to set up',
reason: 'changed something'
}])
Expand All @@ -509,9 +516,9 @@ describe('Licences - Set Up presenter', () => {
text: 'View'
}
],
endDate: '1 February 2025',
endDate: '',
reason: 'Change to special agreement',
startDate: '1 January 2025',
startDate: '1 January 2020',
status: 'approved'
}
])
Expand All @@ -535,7 +542,7 @@ describe('Licences - Set Up presenter', () => {
],
endDate: '',
reason: '',
startDate: '1 January 2025',
startDate: '1 January 2020',
status: 'approved'
}
])
Expand Down Expand Up @@ -586,6 +593,7 @@ describe('Licences - Set Up presenter', () => {
describe('and the licence ends more than 6 years ago', () => {
beforeEach(() => {
const sixYearsAndOneDayAgo = new Date()

sixYearsAndOneDayAgo.setDate(sixYearsAndOneDayAgo.getDate() - 1)
sixYearsAndOneDayAgo.setFullYear(sixYearsAndOneDayAgo.getFullYear() - 6)

Expand Down Expand Up @@ -617,9 +625,10 @@ describe('Licences - Set Up presenter', () => {
.equal('/licences/f91bf145-ce8e-481c-a842-4da90348062b/charge-information/create')
})
})
describe('and the licence \'ends\' more than 6 years ago', () => {
describe('and the licence "ends" more than 6 years ago', () => {
beforeEach(() => {
const sixYearsAndOneDayAgo = new Date()

sixYearsAndOneDayAgo.setDate(sixYearsAndOneDayAgo.getDate() - 1)
sixYearsAndOneDayAgo.setFullYear(sixYearsAndOneDayAgo.getFullYear() - 6)

Expand Down
11 changes: 8 additions & 3 deletions test/services/licences/view-licence-set-up.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ describe('View Licence Set Up service', () => {
id: 'f3fe1275-50ff-4f69-98cb-5a35c17654f3',
createdAt: new Date('2020-01-01'),
status: 'review',
data: { chargeVersion: { changeReason: { description: 'changed something' } } },
data: {
chargeVersion: {
changeReason: { description: 'changed something' },
dateRange: { startDate: '2022-04-01' }
}
},
licenceId: '456'
}
])
Expand Down Expand Up @@ -107,10 +112,10 @@ describe('View Licence Set Up service', () => {
chargeInformation: [
{
action: [],
endDate: '-',
endDate: '',
id: 'f3fe1275-50ff-4f69-98cb-5a35c17654f3',
reason: 'changed something',
startDate: '1 January 2020',
startDate: '1 April 2022',
status: 'review'
},
{
Expand Down
Loading