Skip to content

Commit

Permalink
Create link into service from 2PT review screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozzey committed Jan 14, 2025
1 parent 5fadd09 commit 0803517
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 31 deletions.
4 changes: 2 additions & 2 deletions app/controllers/return-logs-setup.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ async function received(request, h) {
}

async function setup(request, h) {
const { returnLogId } = request.query
const session = await InitiateSessionService.go(returnLogId)
const { fromReview, returnLogId } = request.query
const session = await InitiateSessionService.go(fromReview, returnLogId)

return h.redirect(`/system/return-logs/setup/${session.id}/start`)
}
Expand Down
7 changes: 6 additions & 1 deletion app/presenters/bill-runs/review/base-review.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Big = require('big.js')

const { formatLongDate } = require('../../base.presenter.js')
const DetermineAbstractionPeriodService = require('../../../services/bill-runs/determine-abstraction-periods.service.js')
const FeatureFlagsConfig = require('../../../../config/feature-flags.config.js')

/**
* Calculates the total allocated volume across all review change elements
Expand Down Expand Up @@ -31,7 +32,11 @@ function determineReturnLink(reviewReturn) {
const { returnId, returnStatus } = reviewReturn

if (['due', 'received'].includes(returnStatus)) {
return `/return/internal?returnId=${returnId}`
if (FeatureFlagsConfig.enableSystemReturnsView) {
return `/system/return-logs/setup?returnLogId=${returnId}&fromReview=true`
} else {
return `/return/internal?returnId=${returnId}`
}
}

return `/returns/return?id=${returnId}`
Expand Down
6 changes: 5 additions & 1 deletion app/services/return-logs/setup/initiate-session.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ const SessionModel = require('../../../models/session.model.js')
* At the end when the journey is complete the data from the session will be used to create the edited return log
* and the session record itself deleted.
*
* @param {boolean} fromReview - Used to determine if the session is being created from the
* `/system/licences/{licenceId}/returns` page or the `/system/bill-runs/review/licence/{licenceId}` page. It determines
* what the back link will be on the start page
* @param {string} returnLogId - The UUID of the return log to be fetched
*
* @returns {Promise<module:SessionModel>} the newly created session record
*/
async function go(returnLogId) {
async function go(fromReview, returnLogId) {
const returnLog = await _fetchReturnLog(returnLogId)

const data = _data(returnLog)
data.fromReview = fromReview ?? false

return SessionModel.query().insert({ data }).returning('id')
}
Expand Down
18 changes: 15 additions & 3 deletions test/presenters/bill-runs/review/base-review.presenter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@
// Test framework dependencies
const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const Sinon = require('sinon')

const { describe, it, beforeEach } = (exports.lab = Lab.script())
const { describe, it, beforeEach, afterEach } = (exports.lab = Lab.script())
const { expect } = Code

// Test helpers
const ReturnLogHelper = require('../../../support/helpers/return-log.helper.js')

// Things we need to stub
const FeatureFlagsConfig = require('../../../../config/feature-flags.config.js')

// Thing under test
const BaseReviewPresenter = require('../../../../app/presenters/bill-runs/review/base-review.presenter.js')

describe('Bill Runs Review - Base Review presenter', () => {
beforeEach(() => {
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(true)
})

afterEach(() => {
Sinon.restore()
})

describe('#calculateTotalBillableReturns()', () => {
const reviewChargeElements = [
{ amendedAllocated: 11.513736 },
Expand Down Expand Up @@ -43,7 +55,7 @@ describe('Bill Runs Review - Base Review presenter', () => {
it('returns the link to edit the return', () => {
const result = BaseReviewPresenter.determineReturnLink(reviewReturn)

expect(result).to.equal(`/return/internal?returnId=${returnId}`)
expect(result).to.equal(`/system/return-logs/setup?returnLogId=${returnId}&fromReview=true`)
})
})

Expand All @@ -55,7 +67,7 @@ describe('Bill Runs Review - Base Review presenter', () => {
it('returns the link to edit the return', () => {
const result = BaseReviewPresenter.determineReturnLink(reviewReturn)

expect(result).to.equal(`/return/internal?returnId=${returnId}`)
expect(result).to.equal(`/system/return-logs/setup?returnLogId=${returnId}&fromReview=true`)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const Sinon = require('sinon')

const { describe, it, beforeEach } = (exports.lab = Lab.script())
const { describe, it, beforeEach, afterEach } = (exports.lab = Lab.script())
const { expect } = Code

// Things we need to stub
Expand Down Expand Up @@ -37,6 +37,10 @@ describe('View Licence returns presenter', () => {
Sinon.stub(FeatureFlagsConfig, 'enableSystemReturnsView').value(true)
})

afterEach(() => {
Sinon.restore()
})

describe('when provided with returns data', () => {
it('correctly presents the data', () => {
const result = ViewLicenceReturnsPresenter.go(returnLogs, hasRequirements, auth)
Expand Down
76 changes: 53 additions & 23 deletions test/services/return-logs/setup/initiate-session.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const InitiateSessionService = require('../../../../app/services/return-logs/set

describe('Return Logs - Setup - Initiate Session service', () => {
describe('when called', () => {
let fromReview
let licence
let returnLog

Expand Down Expand Up @@ -46,29 +47,58 @@ describe('Return Logs - Setup - Initiate Session service', () => {
returnLog = await ReturnLogHelper.add({ licenceRef: licence.licenceRef, metadata })
})

it('creates a new session record containing details of the return log', async () => {
const result = await InitiateSessionService.go(returnLog.id)

const matchingSession = await SessionModel.query().findById(result.id)

expect(matchingSession.data).to.equal({
returnLogId: returnLog.id,
licenceId: licence.id,
licenceRef: licence.licenceRef,
startDate: '2022-04-01T00:00:00.000Z',
endDate: '2023-03-31T00:00:00.000Z',
receivedDate: returnLog.receivedDate,
returnReference: returnLog.returnReference,
dueDate: '2023-04-28T00:00:00.000Z',
status: returnLog.status,
underQuery: returnLog.underQuery,
periodStartDay: returnLog.metadata.nald.periodStartDay,
periodStartMonth: returnLog.metadata.nald.periodStartMonth,
periodEndDay: returnLog.metadata.nald.periodEndDay,
periodEndMonth: returnLog.metadata.nald.periodEndMonth,
siteDescription: returnLog.metadata.description,
purposes: 'Test description',
twoPartTariff: returnLog.metadata.isTwoPartTariff
describe('from the "/system/licences/{licenceId}/returns" page', () => {
before(() => {
fromReview = undefined
})

it('creates a new session record containing details of the return log', async () => {
const result = await InitiateSessionService.go(fromReview, returnLog.id)

const matchingSession = await SessionModel.query().findById(result.id)

expect(matchingSession.data).to.equal({
fromReview: false,
returnLogId: returnLog.id,
licenceId: licence.id,
licenceRef: licence.licenceRef,
startDate: '2022-04-01T00:00:00.000Z',
endDate: '2023-03-31T00:00:00.000Z',
receivedDate: returnLog.receivedDate,
returnReference: returnLog.returnReference,
dueDate: '2023-04-28T00:00:00.000Z',
status: returnLog.status,
underQuery: returnLog.underQuery,
periodStartDay: returnLog.metadata.nald.periodStartDay,
periodStartMonth: returnLog.metadata.nald.periodStartMonth,
periodEndDay: returnLog.metadata.nald.periodEndDay,
periodEndMonth: returnLog.metadata.nald.periodEndMonth,
siteDescription: returnLog.metadata.description,
purposes: 'Test description',
twoPartTariff: returnLog.metadata.isTwoPartTariff
})
})

it('sets "fromReview" to false', async () => {
const result = await InitiateSessionService.go(fromReview, returnLog.id)

const matchingSession = await SessionModel.query().findById(result.id)

expect(matchingSession.data.fromReview).to.be.false()
})
})

describe('from the "/system/bill-runs/review/licence/{licenceId}" page', () => {
before(() => {
fromReview = true
})

it('sets "fromReview" to true', async () => {
const result = await InitiateSessionService.go(fromReview, returnLog.id)

const matchingSession = await SessionModel.query().findById(result.id)

expect(matchingSession.data.fromReview).to.be.true()
})
})
})
Expand Down

0 comments on commit 0803517

Please sign in to comment.