Skip to content

Commit

Permalink
Merge branch 'main' into trigger-tpt-supp-bill-run-pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozzey authored Sep 4, 2024
2 parents ab75ea9 + 896ac8d commit 3eaaa20
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 6 deletions.
29 changes: 24 additions & 5 deletions app/presenters/licences/view-licence.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,22 @@ function _licenceName (licence) {
}

function _notification (licence) {
const { includeInPresrocBilling, includeInSrocBilling } = licence
const baseMessage = 'This licence has been marked for the next supplementary bill run'
const { includeInPresrocBilling, includeInSrocBilling, licenceSupplementaryYears } = licence
const baseMessage = 'This licence has been marked for the next '

if (licenceSupplementaryYears.length > 0) {
return _tptNotification(baseMessage, includeInPresrocBilling, includeInSrocBilling)
}

if (includeInPresrocBilling === 'yes' && includeInSrocBilling === true) {
return baseMessage + 's for the current and old charge schemes.'
return baseMessage + 'supplementary bill runs for the current and old charge schemes.'
}
if (includeInPresrocBilling === 'yes') {
return baseMessage + ' for the old charge scheme.'
return baseMessage + 'supplementary bill run for the old charge scheme.'
}

if (includeInSrocBilling === true) {
return baseMessage + '.'
return baseMessage + 'supplementary bill run.'
}

return null
Expand All @@ -77,6 +81,21 @@ function _roles (auth) {
})
}

function _tptNotification (baseMessage, includeInPresrocBilling, includeInSrocBilling) {
if (includeInPresrocBilling === 'yes' && includeInSrocBilling === true) {
return baseMessage + 'two-part tariff supplementary bill run and supplementary bill runs for the current and old charge schemes.'
}
if (includeInPresrocBilling === 'yes') {
return baseMessage + 'two-part tariff supplementary bill run and the supplementary bill run for the old charge scheme.'
}

if (includeInSrocBilling === true) {
return baseMessage + 'two-part tariff supplementary bill run and the supplementary bill run.'
}

return baseMessage + 'two-part tariff supplementary bill run.'
}

function _warning (ends) {
const today = new Date()

Expand Down
8 changes: 8 additions & 0 deletions app/services/licences/fetch-licence.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ async function _fetch (licenceId) {
])
.modify('licenceName')
.modify('primaryUser')
.withGraphFetched('licenceSupplementaryYears')
.modifyGraph('licenceSupplementaryYears', (builder) => {
builder
.select([
'id'
])
.where('twoPartTariff', true)
})
.withGraphFetched('workflows')
.modifyGraph('workflows', (builder) => {
builder
Expand Down
55 changes: 54 additions & 1 deletion test/presenters/licences/view-licence.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('View Licence presenter', () => {
})

describe('the "notification" property', () => {
describe('when the licence has NOT been flagged for either supplementary bill run', () => {
describe('when the licence has NOT been flagged for any supplementary bill runs', () => {
it('returns "null"', () => {
const result = ViewLicencePresenter.go(licence, auth)

Expand Down Expand Up @@ -113,6 +113,58 @@ describe('View Licence presenter', () => {
expect(result.notification).to.equal('This licence has been marked for the next supplementary bill runs for the current and old charge schemes.')
})
})

describe('when the licence has been flagged just for the next TPT supplementary bill run', () => {
beforeEach(() => {
licence.licenceSupplementaryYears.push({ id: '1636ab31-3b79-4fec-9e51-be89835e9981' })
})

it('returns a notification just for TPT supplementary', () => {
const result = ViewLicencePresenter.go(licence, auth)

expect(result.notification).to.equal('This licence has been marked for the next two-part tariff supplementary bill run.')
})
})

describe('when the licence has been flagged for the next TPT & PRESROC supplementary bill runs', () => {
beforeEach(() => {
licence.licenceSupplementaryYears.push({ id: '1636ab31-3b79-4fec-9e51-be89835e9981' })
licence.includeInPresrocBilling = 'yes'
})

it('returns a notification for TPT & PRESROC supplementary', () => {
const result = ViewLicencePresenter.go(licence, auth)

expect(result.notification).to.equal('This licence has been marked for the next two-part tariff supplementary bill run and the supplementary bill run for the old charge scheme.')
})
})

describe('when the licence has been flagged for the next TPT & SROC supplementary bill runs', () => {
beforeEach(() => {
licence.licenceSupplementaryYears.push({ id: '1636ab31-3b79-4fec-9e51-be89835e9981' })
licence.includeInSrocBilling = true
})

it('returns a notification for TPT & SROC supplementary', () => {
const result = ViewLicencePresenter.go(licence, auth)

expect(result.notification).to.equal('This licence has been marked for the next two-part tariff supplementary bill run and the supplementary bill run.')
})
})

describe('when the licence has been flagged for the next TPT, PRESROC & SROC supplementary bill runs', () => {
beforeEach(() => {
licence.licenceSupplementaryYears.push({ id: '1636ab31-3b79-4fec-9e51-be89835e9981' })
licence.includeInPresrocBilling = 'yes'
licence.includeInSrocBilling = true
})

it('returns a notification for TPT, PRESROC & SROC supplementary', () => {
const result = ViewLicencePresenter.go(licence, auth)

expect(result.notification).to.equal('This licence has been marked for the next two-part tariff supplementary bill run and supplementary bill runs for the current and old charge schemes.')
})
})
})

describe('the "roles" property', () => {
Expand Down Expand Up @@ -280,6 +332,7 @@ function _licence () {
}
}
},
licenceSupplementaryYears: [],
workflows: [{ id: 'b6f44c94-25e4-4ca8-a7db-364534157ba7', status: 'to_setup' }]
})

Expand Down
12 changes: 12 additions & 0 deletions test/services/licences/fetch-licence.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,28 @@ const { expect } = Code
// Test helpers
const LicenceHelper = require('../../support/helpers/licence.helper.js')
const LicenceModel = require('../../../app/models/licence.model.js')
const licenceSupplementaryYearHelper = require('../../support/helpers/licence-supplementary-year.helper.js')
const WorkflowHelper = require('../../support/helpers/workflow.helper.js')

// Thing under test
const FetchLicenceService = require('../../../app/services/licences/fetch-licence.service.js')

describe('Fetch Licence service', () => {
let licence
let licenceSupplementaryYearId
let workflow

describe('when there is a matching licence', () => {
beforeEach(async () => {
licence = await LicenceHelper.add()

const licenceSupplementaryYear = await licenceSupplementaryYearHelper.add({
licenceId: licence.id,
twoPartTariff: true
})

licenceSupplementaryYearId = licenceSupplementaryYear.id

// We add two workflow records: one reflects that the licence is in workflow, so of that it previously was but
// has been dealt with. We want to ensure these soft-deleted records are ignored so licences are not flagged
// as changed incorrectly
Expand All @@ -43,6 +52,9 @@ describe('Fetch Licence service', () => {
revokedDate: null,
lapsedDate: null,
licenceDocumentHeader: null,
licenceSupplementaryYears: [{
id: licenceSupplementaryYearId
}],
workflows: [{
id: workflow.id,
status: workflow.status
Expand Down
1 change: 1 addition & 0 deletions test/services/licences/view-licence.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function _licence () {
}
}
},
licenceSupplementaryYears: [],
workflows: [{ id: 'b6f44c94-25e4-4ca8-a7db-364534157ba7', status: 'to_setup' }]
})

Expand Down

0 comments on commit 3eaaa20

Please sign in to comment.