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

Update bill run setup journey to use new session #983

Merged
merged 4 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/presenters/bill-runs/setup/create.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/bill-runs/setup/region.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/presenters/bill-runs/setup/season.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/presenters/bill-runs/setup/type.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/presenters/bill-runs/setup/year.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/services/bill-runs/setup/create.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
6 changes: 3 additions & 3 deletions app/services/bill-runs/setup/exists.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions app/services/bill-runs/setup/submit-region.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
6 changes: 2 additions & 4 deletions app/services/bill-runs/setup/submit-season.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions app/services/bill-runs/setup/submit-type.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions app/services/bill-runs/setup/submit-year.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions test/presenters/bill-runs/setup/create.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Bill Runs Setup Create presenter', () => {
beforeEach(() => {
session = {
id: '98ad3a1f-8e4f-490a-be05-0aece6755466',
data: { type: 'annual' }
type: 'annual'
}

matchingBillRun = {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/bill-runs/setup/region.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/bill-runs/setup/season.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/bill-runs/setup/type.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/bill-runs/setup/year.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 8 additions & 0 deletions test/services/bill-runs/setup/create.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
})
Expand All @@ -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 }
})
Expand All @@ -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', () => {
Expand Down Expand Up @@ -147,6 +153,7 @@ describe('Bill Runs Setup Create service', () => {
season: 'summer'
}
})
session.$afterFind()

existsResults = { matchResults: [], session, yearToUse: 2022 }
})
Expand All @@ -168,6 +175,7 @@ describe('Bill Runs Setup Create service', () => {
year: 2023
}
})
session.$afterFind()

existsResults = { matchResults: [], session, yearToUse: 2023 }
})
Expand Down
4 changes: 2 additions & 2 deletions test/services/bill-runs/setup/submit-region.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand All @@ -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()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion test/services/bill-runs/setup/submit-type.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions test/services/bill-runs/setup/submit-year.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand All @@ -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()
})
})
Expand Down
Loading