diff --git a/app/presenters/bill-runs/setup/create.presenter.js b/app/presenters/bill-runs/setup/create.presenter.js index 6c46876d91..7ebc517cf7 100644 --- a/app/presenters/bill-runs/setup/create.presenter.js +++ b/app/presenters/bill-runs/setup/create.presenter.js @@ -54,7 +54,7 @@ function go (session, billRun) { } function _backLink (session) { - const { type, year } = session.data + const { type, year } = session if (!type.startsWith('two_part')) { return `/system/bill-runs/setup/${session.id}/region` diff --git a/app/presenters/bill-runs/setup/region.presenter.js b/app/presenters/bill-runs/setup/region.presenter.js index 607e0c55d1..c2be29a81e 100644 --- a/app/presenters/bill-runs/setup/region.presenter.js +++ b/app/presenters/bill-runs/setup/region.presenter.js @@ -17,7 +17,7 @@ function go (session, regions) { return { sessionId: session.id, regions, - selectedRegion: session.data.region ? session.data.region : null + selectedRegion: session.region ? session.region : null } } diff --git a/app/presenters/bill-runs/setup/season.presenter.js b/app/presenters/bill-runs/setup/season.presenter.js index 5713498191..f66f23af8a 100644 --- a/app/presenters/bill-runs/setup/season.presenter.js +++ b/app/presenters/bill-runs/setup/season.presenter.js @@ -15,7 +15,7 @@ function go (session) { return { sessionId: session.id, - selectedSeason: session.data.season ? session.data.season : null + selectedSeason: session.season ? session.season : null } } diff --git a/app/presenters/bill-runs/setup/type.presenter.js b/app/presenters/bill-runs/setup/type.presenter.js index 0612f7c69a..60668d1f12 100644 --- a/app/presenters/bill-runs/setup/type.presenter.js +++ b/app/presenters/bill-runs/setup/type.presenter.js @@ -15,7 +15,7 @@ function go (session) { return { sessionId: session.id, - selectedType: session.data.type ? session.data.type : null + selectedType: session.type ? session.type : null } } diff --git a/app/presenters/bill-runs/setup/year.presenter.js b/app/presenters/bill-runs/setup/year.presenter.js index b1845a2f37..d2186a0a33 100644 --- a/app/presenters/bill-runs/setup/year.presenter.js +++ b/app/presenters/bill-runs/setup/year.presenter.js @@ -15,7 +15,7 @@ function go (session) { return { sessionId: session.id, - selectedYear: session.data.year ? session.data.year : null + selectedYear: session.year ? session.year : null } } diff --git a/app/services/bill-runs/setup/create.service.js b/app/services/bill-runs/setup/create.service.js index 90f24e3c95..eda6ce4a30 100644 --- a/app/services/bill-runs/setup/create.service.js +++ b/app/services/bill-runs/setup/create.service.js @@ -25,7 +25,7 @@ const StartBillRunProcessService = require('../start-bill-run-process.service.js */ async function go (user, existsResults) { const { matchResults, session, yearToUse } = existsResults - const { region: regionId, type, summer } = session.data + const { region: regionId, type, summer } = session const existingBillRun = matchResults[0] diff --git a/app/services/bill-runs/setup/exists.service.js b/app/services/bill-runs/setup/exists.service.js index 16ba6a12fd..3434b4e3fe 100644 --- a/app/services/bill-runs/setup/exists.service.js +++ b/app/services/bill-runs/setup/exists.service.js @@ -38,7 +38,7 @@ const SessionModel = require('../../../models/session.model.js') async function go (sessionId) { const session = await SessionModel.query().findById(sessionId) - const { region, type, year } = session.data + const { region, type, year } = session const yearToUse = await DetermineFinancialYearEndService.go(region, type, year) const matchResults = await _fetchMatchingBillRun(session, yearToUse) @@ -54,13 +54,13 @@ async function go (sessionId) { } async function _fetchMatchingBillRun (session, year) { - const { region, season, type } = session.data + const { region, season, type } = session return DetermineBlockingBillRunService.go(region, type, year, season) } function _pageData (session, matchResults) { - const { type } = session.data + const { type } = session // No matches so we can create the bill run if (matchResults.length === 0) { diff --git a/app/services/bill-runs/setup/submit-region.service.js b/app/services/bill-runs/setup/submit-region.service.js index 4360e3e480..2a6ecfb0e3 100644 --- a/app/services/bill-runs/setup/submit-region.service.js +++ b/app/services/bill-runs/setup/submit-region.service.js @@ -40,7 +40,7 @@ async function go (sessionId, payload) { await _save(session, payload) // The journey is complete (we don't need any details) if the bill run type is not 2PT - return { setupComplete: !session.data.type.startsWith('two_part') } + return { setupComplete: !session.type.startsWith('two_part') } } const formattedData = RegionPresenter.go(session, regions) @@ -52,7 +52,7 @@ async function go (sessionId, payload) { } async function _save (session, payload) { - const currentData = session.data + const currentData = session currentData.region = payload.region diff --git a/app/services/bill-runs/setup/submit-season.service.js b/app/services/bill-runs/setup/submit-season.service.js index bce40eac53..7d7343fe94 100644 --- a/app/services/bill-runs/setup/submit-season.service.js +++ b/app/services/bill-runs/setup/submit-season.service.js @@ -48,11 +48,9 @@ async function go (sessionId, payload) { } async function _save (session, payload) { - const currentData = session.data + session.season = payload.season - currentData.season = payload.season - - return session.$query().patch({ data: currentData }) + return session.$update() } function _validate (payload) { diff --git a/app/services/bill-runs/setup/submit-type.service.js b/app/services/bill-runs/setup/submit-type.service.js index a7139bf4ac..f8398ca464 100644 --- a/app/services/bill-runs/setup/submit-type.service.js +++ b/app/services/bill-runs/setup/submit-type.service.js @@ -48,11 +48,9 @@ async function go (sessionId, payload) { } async function _save (session, payload) { - const currentData = session.data + session.type = payload.type - currentData.type = payload.type - - return session.$query().patch({ data: currentData }) + return session.$update() } function _validate (payload) { diff --git a/app/services/bill-runs/setup/submit-year.service.js b/app/services/bill-runs/setup/submit-year.service.js index 45aa7d78af..85083760c3 100644 --- a/app/services/bill-runs/setup/submit-year.service.js +++ b/app/services/bill-runs/setup/submit-year.service.js @@ -37,7 +37,7 @@ async function go (sessionId, payload) { if (!validationResult) { await _save(session, payload) - return { setupComplete: ['2024', '2023'].includes(session.data.year) } + return { setupComplete: ['2024', '2023'].includes(session.year) } } const formattedData = YearPresenter.go(session) @@ -49,11 +49,9 @@ async function go (sessionId, payload) { } async function _save (session, payload) { - const currentData = session.data + session.year = payload.year - currentData.year = payload.year - - return session.$query().patch({ data: currentData }) + return session.$update() } function _validate (payload, regions) { diff --git a/test/presenters/bill-runs/setup/create.presenter.test.js b/test/presenters/bill-runs/setup/create.presenter.test.js index 0208d4ff02..6a754f1c69 100644 --- a/test/presenters/bill-runs/setup/create.presenter.test.js +++ b/test/presenters/bill-runs/setup/create.presenter.test.js @@ -18,7 +18,7 @@ describe('Bill Runs Setup Create presenter', () => { beforeEach(() => { session = { id: '98ad3a1f-8e4f-490a-be05-0aece6755466', - data: { type: 'annual' } + type: 'annual' } matchingBillRun = { @@ -55,7 +55,7 @@ describe('Bill Runs Setup Create presenter', () => { describe("the 'backLink' property", () => { describe("when the selected bill run type is not 'two_part_tariff'", () => { beforeEach(() => { - session.data.type = 'supplementary' + session.type = 'supplementary' }) it('returns a link to the region page', () => { @@ -67,12 +67,12 @@ describe('Bill Runs Setup Create presenter', () => { describe("when the selected bill run type is 'two_part_tariff'", () => { beforeEach(() => { - session.data.type = 'two_part_tariff' + session.type = 'two_part_tariff' }) describe('and the selected financial year is in the SROC period', () => { beforeEach(() => { - session.data.year = '2023' + session.year = '2023' }) it('returns a link to the financial year page', () => { @@ -84,7 +84,7 @@ describe('Bill Runs Setup Create presenter', () => { describe('and the selected financial year is in the PRESROC period', () => { beforeEach(() => { - session.data.year = '2022' + session.year = '2022' }) it('returns a link to the season page', () => { diff --git a/test/presenters/bill-runs/setup/region.presenter.test.js b/test/presenters/bill-runs/setup/region.presenter.test.js index b19b8203da..364af313f2 100644 --- a/test/presenters/bill-runs/setup/region.presenter.test.js +++ b/test/presenters/bill-runs/setup/region.presenter.test.js @@ -41,7 +41,7 @@ describe('Bill Runs Setup Region presenter', () => { describe('where the user has previously selected a bill run region', () => { beforeEach(() => { - session.data.region = 'Stormlands' + session.region = 'Stormlands' }) it('correctly presents the data', () => { diff --git a/test/presenters/bill-runs/setup/season.presenter.test.js b/test/presenters/bill-runs/setup/season.presenter.test.js index fc5e0332bc..d6443b84c8 100644 --- a/test/presenters/bill-runs/setup/season.presenter.test.js +++ b/test/presenters/bill-runs/setup/season.presenter.test.js @@ -34,7 +34,7 @@ describe('Bill Runs Setup Season presenter', () => { describe('where the user has previously selected a season', () => { beforeEach(() => { - session.data.season = 'summer' + session.season = 'summer' }) it('correctly presents the data', () => { diff --git a/test/presenters/bill-runs/setup/type.presenter.test.js b/test/presenters/bill-runs/setup/type.presenter.test.js index 7b5956e93c..e7c736b1f9 100644 --- a/test/presenters/bill-runs/setup/type.presenter.test.js +++ b/test/presenters/bill-runs/setup/type.presenter.test.js @@ -34,7 +34,7 @@ describe('Bill Runs Setup Type presenter', () => { describe('where the user has previously selected a bill run type', () => { beforeEach(() => { - session.data.type = 'annual' + session.type = 'annual' }) it('correctly presents the data', () => { diff --git a/test/presenters/bill-runs/setup/year.presenter.test.js b/test/presenters/bill-runs/setup/year.presenter.test.js index 667e264c53..53ba68575d 100644 --- a/test/presenters/bill-runs/setup/year.presenter.test.js +++ b/test/presenters/bill-runs/setup/year.presenter.test.js @@ -34,7 +34,7 @@ describe('Bill Runs Setup Year presenter', () => { describe('where the user has previously selected a financial year', () => { beforeEach(() => { - session.data.year = 2022 + session.year = 2022 }) it('correctly presents the data', () => { diff --git a/test/services/bill-runs/setup/create.service.test.js b/test/services/bill-runs/setup/create.service.test.js index 7bf023e00f..626e41c7d5 100644 --- a/test/services/bill-runs/setup/create.service.test.js +++ b/test/services/bill-runs/setup/create.service.test.js @@ -44,6 +44,10 @@ describe('Bill Runs Setup Create service', () => { session = await SessionHelper.add({ data: { region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', type: 'annual' } }) + // NOTE: We make these additional $afterFind() calls to trigger the hook that would have been called when the + // create service queries for the session. The hook elevates properties from `data` onto the session instance + // itself. Without this the tests fail though the service works fine. + session.$afterFind() existsResults = { matchResults: [], session, yearToUse: 2024 } }) @@ -62,6 +66,7 @@ describe('Bill Runs Setup Create service', () => { session = await SessionHelper.add({ data: { region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', type: 'annual' } }) + session.$afterFind() existsResults = { matchResults: [], session, yearToUse: 2024 } }) @@ -84,6 +89,7 @@ describe('Bill Runs Setup Create service', () => { session = await SessionHelper.add({ data: { region: '19a027c6-4aad-47d3-80e3-3917a4579a5b', type: 'supplementary' } }) + session.$afterFind() }) describe('and there were no matching bill runs', () => { @@ -147,6 +153,7 @@ describe('Bill Runs Setup Create service', () => { season: 'summer' } }) + session.$afterFind() existsResults = { matchResults: [], session, yearToUse: 2022 } }) @@ -168,6 +175,7 @@ describe('Bill Runs Setup Create service', () => { year: 2023 } }) + session.$afterFind() existsResults = { matchResults: [], session, yearToUse: 2023 } }) diff --git a/test/services/bill-runs/setup/submit-region.service.test.js b/test/services/bill-runs/setup/submit-region.service.test.js index 9ae00b7e7e..d745dfa597 100644 --- a/test/services/bill-runs/setup/submit-region.service.test.js +++ b/test/services/bill-runs/setup/submit-region.service.test.js @@ -58,7 +58,7 @@ describe('Bill Runs Setup Submit Region service', () => { const refreshedSession = await session.$query() - expect(refreshedSession.data.region).to.equal('19a027c6-4aad-47d3-80e3-3917a4579a5b') + expect(refreshedSession.region).to.equal('19a027c6-4aad-47d3-80e3-3917a4579a5b') expect(result.setupComplete).to.be.true() }) }) @@ -73,7 +73,7 @@ describe('Bill Runs Setup Submit Region service', () => { const refreshedSession = await session.$query() - expect(refreshedSession.data.region).to.equal('19a027c6-4aad-47d3-80e3-3917a4579a5b') + expect(refreshedSession.region).to.equal('19a027c6-4aad-47d3-80e3-3917a4579a5b') expect(result.setupComplete).to.be.false() }) }) diff --git a/test/services/bill-runs/setup/submit-season.service.test.js b/test/services/bill-runs/setup/submit-season.service.test.js index aff5eb7e7c..14450a768a 100644 --- a/test/services/bill-runs/setup/submit-season.service.test.js +++ b/test/services/bill-runs/setup/submit-season.service.test.js @@ -37,7 +37,7 @@ describe('Bill Runs Setup Submit Season service', () => { const refreshedSession = await session.$query() - expect(refreshedSession.data.season).to.equal('summer') + expect(refreshedSession.season).to.equal('summer') }) it('returns an empty object (no page data is needed for a redirect)', async () => { diff --git a/test/services/bill-runs/setup/submit-type.service.test.js b/test/services/bill-runs/setup/submit-type.service.test.js index 6e477d49c7..fb273b1143 100644 --- a/test/services/bill-runs/setup/submit-type.service.test.js +++ b/test/services/bill-runs/setup/submit-type.service.test.js @@ -37,7 +37,7 @@ describe('Bill Runs Setup Submit Type service', () => { const refreshedSession = await session.$query() - expect(refreshedSession.data.type).to.equal('annual') + expect(refreshedSession.type).to.equal('annual') }) it('returns an empty object (no page data is needed for a redirect)', async () => { diff --git a/test/services/bill-runs/setup/submit-year.service.test.js b/test/services/bill-runs/setup/submit-year.service.test.js index 0d10a0db68..76c79f5d9c 100644 --- a/test/services/bill-runs/setup/submit-year.service.test.js +++ b/test/services/bill-runs/setup/submit-year.service.test.js @@ -38,7 +38,7 @@ describe('Bill Runs Setup Submit Year service', () => { const refreshedSession = await session.$query() - expect(refreshedSession.data.year).to.equal('2023') + expect(refreshedSession.year).to.equal('2023') expect(result.setupComplete).to.be.true() }) }) @@ -55,7 +55,7 @@ describe('Bill Runs Setup Submit Year service', () => { const refreshedSession = await session.$query() - expect(refreshedSession.data.year).to.equal('2022') + expect(refreshedSession.year).to.equal('2022') expect(result.setupComplete).to.be.false() }) })