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

Add pre sroc returns flagging to service #1335

Merged
merged 9 commits into from
Sep 24, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const { ref } = require('objection')

const ReturnLogModel = require('../../../models/return-log.model.js')
const LicenceModel = require('../../../models/licence.model.js')

const SROC_START_DATE = new Date('2022-04-01')

Expand All @@ -34,7 +35,14 @@ async function go (returnLogId) {
flagForBilling: false
}

if (startDate < SROC_START_DATE) {
// As the returns start date is before the SROC start date, we need to flag the return for pre sroc billing
await _flagLicenceForPreSrocSupplementary(licence.id)
}

if (endDate < SROC_START_DATE) {
// If the end date of the return is before the start of SROC then we do not need to flag the licence for sroc
// supplementary billing
return result
}

Expand Down Expand Up @@ -63,6 +71,12 @@ async function _fetchReturnLog (returnLogId) {
})
}

async function _flagLicenceForPreSrocSupplementary (licenceId) {
return LicenceModel.query()
.patch({ includeInPresrocBilling: 'yes' })
.where('id', licenceId)
}

module.exports = {
go
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { expect } = Code

// Test helpers
const LicenceHelper = require('../../../support/helpers/licence.helper.js')
const LicenceModel = require('../../../../app/models/licence.model.js')
const ReturnLogHelper = require('../../../support/helpers/return-log.helper.js')

// Thing under test
Expand Down Expand Up @@ -44,6 +45,14 @@ describe('Determine Return Log Years Service', () => {
expect(result.flagForBilling).to.equal(false)
expect(result.twoPartTariff).to.equal(false)
})

it('does not flag the licence for pre sroc supplementary billing', async () => {
await DetermineReturnLogYearsService.go(returnLog.id)

const result = await LicenceModel.query().select(['includeInPresrocBilling']).where('id', licence.id)

expect(result[0].includeInPresrocBilling).to.equal('no')
})
})

describe('and two-part tariff is true', () => {
Expand Down Expand Up @@ -77,6 +86,14 @@ describe('Determine Return Log Years Service', () => {
expect(result.flagForBilling).to.equal(false)
expect(result.twoPartTariff).to.equal(true)
})

it('flags the licence for pre sroc supplementary billing', async () => {
await DetermineReturnLogYearsService.go(returnLog.id)

const result = await LicenceModel.query().select(['includeInPresrocBilling']).where('id', licence.id)

expect(result[0].includeInPresrocBilling).to.equal('yes')
})
})

describe('and the end date is after the SROC billing start date', () => {
Expand All @@ -95,6 +112,14 @@ describe('Determine Return Log Years Service', () => {
expect(result.flagForBilling).to.equal(true)
expect(result.twoPartTariff).to.equal(true)
})

it('flags the licence for pre sroc supplementary billing', async () => {
await DetermineReturnLogYearsService.go(returnLog.id)

const result = await LicenceModel.query().select(['includeInPresrocBilling']).where('id', licence.id)

expect(result[0].includeInPresrocBilling).to.equal('yes')
})
})
})
})
Expand Down
Loading