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

Trigger 2PT Supplementary Bill Run #1259

Merged
merged 10 commits into from
Aug 16, 2024
2 changes: 1 addition & 1 deletion app/controllers/bill-runs-setup.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async function type (request, h) {

return h.view('bill-runs/setup/type.njk', {
activeNavBar: 'bill-runs',
pageTitle: 'Select a bill run type',
pageTitle: 'Select bill run type',
...pageData
})
}
Expand Down
10 changes: 10 additions & 0 deletions app/services/bill-runs/setup/submit-region.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ async function go (sessionId, payload) {
if (!validationResult) {
await _save(session, payload)

// Temporary if statement to end the journey if the bill run is for two-part tariff supplementary
if (session.type === 'two_part_supplementary') {
const temporaryFormattedData = RegionPresenter.go(session, regions)

return {
error: { text: 'Currently you can progress no further for a two-part tariff supplementary bill run' },
...temporaryFormattedData
}
}

// The journey is complete (we don't need any details) if the bill run type is not 2PT
return { setupComplete: !session.type.startsWith('two_part') }
}
Expand Down
1 change: 1 addition & 0 deletions app/validators/bill-runs/setup/type.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Joi = require('joi')
const VALID_VALUES = [
'annual',
'supplementary',
'two_part_supplementary',
'two_part_tariff'
]

Expand Down
13 changes: 12 additions & 1 deletion app/views/bill-runs/setup/type.njk
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@
{
text: 'Two-part tariff',
value: 'two_part_tariff',
checked: 'two_part_tariff' == selectedType
checked: 'two_part_tariff' == selectedType,
hint: {
text: 'Second part charges only'
}
},
{
text: 'Two-part tariff supplementary',
value: 'two_part_supplementary',
checked: 'two_part_supplementary' == selectedType,
hint: {
text: 'Second part charges for the current charge scheme only'
}
}
]
}) }}
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/bill-runs-setup.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('Bill Runs Setup controller', () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Select a bill run type')
expect(response.payload).to.contain('Select bill run type')
})
})
})
Expand Down
19 changes: 19 additions & 0 deletions test/services/bill-runs/setup/submit-region.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ describe('Bill Runs Setup Submit Region service', () => {
expect(result.setupComplete).to.be.false()
})
})

describe('and the bill run type was two-part tariff supplementary', () => {
beforeEach(async () => {
session = await SessionHelper.add({ data: { type: 'two_part_supplementary' } })
})

it('returns page data needed to re-render the view including the error', async () => {
const result = await SubmitRegionService.go(session.id, payload)

expect(result).to.equal({
sessionId: session.id,
regions,
selectedRegion: payload.region,
error: {
text: 'Currently you can progress no further for a two-part tariff supplementary bill run'
}
})
})
})
})

describe('with an invalid payload', () => {
Expand Down
Loading