Skip to content

Commit

Permalink
Mark for supplementary billing service and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Beckyrose200 committed Sep 9, 2024
1 parent e0536b5 commit d4190ce
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict'

/**
* Formats the two part tariff review data ready for presenting in the amend adjustment factor page
* @module MarkForSupplementaryBillingPresenter
*/

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

function go (licence) {
return {
licenceId: licence.id,
licenceRef: licence.licenceRef,
financialYears: _yearsToDisplay()
}
}

function _yearsToDisplay () {
const currentDate = new Date()
const currentYear = currentDate.getFullYear()
const currentMonth = currentDate.getMonth()
const years = []
let preSrocYears = false

// Determine the financial year we are in
const financialYearEnd = (currentMonth >= 3) ? currentYear + 1 : currentYear

for (let i = 0; i < 6; i++) {
const year = financialYearEnd - i

if (year > 2022) {
years.push({
text: `${formatFinancialYear(year)}`,
value: year
})
} else if (!preSrocYears) {
years.push({
text: 'Before 2022',
value: 'preSroc',
hint: {
text: 'Old charge scheme'
}
})

preSrocYears = true
}
}

return years
}

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

/**
* Orchestrates flagging a licence for supplementary billing
* @module MarkForSupplementaryBillingService
*/

const LicenceModel = require('../../../../app/models/licence.model.js')
const MarkForSupplementaryBillingPresenter = require('../../../presenters/licences/supplementary/mark-for-supplementary-billing.presenter.js')

/**
* Orchestrates fetching and presenting the data needed for the licence mark for supplementary billing page
*
* @param {string} licenceId - the UUID of the licence being flagged for supplementary billing
*
* @returns {Promise<object>} an object representing the `pageData` needed by the mark for supplementary billing page.
* It contains details of the last 6 years from todays date and the licence details.
*/
async function go (licenceId) {
const licenceData = await _fetchLicenceData(licenceId)

const pageData = MarkForSupplementaryBillingPresenter.go(licenceData)

return pageData
}

async function _fetchLicenceData (licenceId) {
return LicenceModel.query()
.findById(licenceId)
.select([
'id',
'licenceRef'
])
}

module.exports = {
go
}

0 comments on commit d4190ce

Please sign in to comment.