Skip to content

Commit

Permalink
Fix licence agreement action links (#1065)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangoulding authored May 31, 2024
1 parent 825ad2d commit 60764ba
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/presenters/licences/set-up.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function _agreementActionLinks (commonData, agreement, auth) {
return []
}

if (_endsSixYearsAgo(commonData.ends)) {
return []
}

const actionLinks = []
const hasNotEnded = agreement.endDate === null
const is2PTAgreement = _financialAgreementCode(agreement) === 'S127'
Expand Down
56 changes: 55 additions & 1 deletion test/presenters/licences/set-up.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ describe('Licence Set Up presenter', () => {
}
}

commonData = { licenceId: 'f91bf145-ce8e-481c-a842-4da90348062b' }
const lessThanSixYearsAgo = new Date()

commonData = {
licenceId: 'f91bf145-ce8e-481c-a842-4da90348062b',
ends: {
date: lessThanSixYearsAgo
}
}

chargeVersions = []
workflows = []
agreements = []
})

describe('when provided with populated licence set up data', () => {
Expand Down Expand Up @@ -287,6 +298,49 @@ describe('Licence Set Up presenter', () => {
})
})
})

describe('when the licence is less than 6 years old and all the actions are available for an agreement', () => {
beforeEach(() => {
agreement.financialAgreements[0].financialAgreementCode = 'S127'
})

it('shows delete, end and recalculate bills actions', () => {
const result = SetUpPresenter.go(chargeVersions, workflows, agreements, auth, commonData)

expect(result.agreements[0].action).to.equal([
{
link: '/licences/f91bf145-ce8e-481c-a842-4da90348062b/agreements/123/delete',
text: 'Delete'
},
{
link: '/licences/f91bf145-ce8e-481c-a842-4da90348062b/agreements/123/end',
text: 'End'
},
{
link: '/licences/f91bf145-ce8e-481c-a842-4da90348062b/mark-for-supplementary-billing',
text: 'Recalculate bills'
}
])
})
})

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)

commonData.ends = {
date: sixYearsAndOneDayAgo
}
})

it('shows delete, end and recalculate bills actions', () => {
const result = SetUpPresenter.go(chargeVersions, workflows, agreements, auth, commonData)

expect(result.agreements[0].action).to.equal([])
})
})
})

describe('that includes both charge versions and workflows', () => {
Expand Down

0 comments on commit 60764ba

Please sign in to comment.