Skip to content

Commit

Permalink
Merge branch 'main' into refactor-supplementary-billing-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Beckyrose200 authored Nov 26, 2024
2 parents 74cce73 + ad76539 commit d025eb4
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 46 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
COOKIE_SECRET: somethingverysecrethere
GOOGLE_ANALYTICS_PROPERTY_ID: ga-test
NOTIFY_CALLBACK_TOKEN: some-token
ENABLE_SYSTEM_LICENCE_VIEW: true

steps:
# Downloads a copy of the code in your repository before running CI tests
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
22
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 53 additions & 7 deletions src/internal/modules/gauging-stations/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const { waterAbstractionAlerts: isWaterAbstractionAlertsEnabled } = require('../
const { hasScope } = require('../../lib/permissions')
const { manageGaugingStationLicenceLinks, hofNotifications } = require('../../lib/constants').scope

const { featureToggles: featureFlags } = require('../../config.js')

/**
* Main Gauging station page
* All data is loaded via shared pre-handlers
Expand Down Expand Up @@ -248,11 +250,19 @@ const postNewTaggingCheckYourAnswers = async (request, h) => {
const getNewTaggingFlowComplete = (request, h) => {
const { licenceNumber } = session.get(request)
session.clear(request)

let monitoringStationUrl = `/monitoring-stations/${request.params.gaugingStationId}/`

if (featureFlags.enableMonitoringStationsView) {
monitoringStationUrl = `/system${monitoringStationUrl}`
}

return h.view('nunjucks/gauging-stations/new-tag-complete', {
pageTitle: 'Licence added to monitoring station',
back: null,
licenceRef: licenceNumber.value,
gaugingStationId: request.params.gaugingStationId
gaugingStationId: request.params.gaugingStationId,
monitoringStationUrl
})
}

Expand All @@ -268,6 +278,14 @@ const getRemoveTags = async (request, h) => {
const { licenceGaugingStations } = request.pre
const { data } = licenceGaugingStations

// NOTE: We have updated this just for correctness! Back links are ignored in the legacy UI because of the back link
// high-jacking implemented in client-side JavaScript we send to the browser.
let back = `/monitoring-stations/${request.params.gaugingStationId}/`

if (featureFlags.enableMonitoringStationsView) {
back = `/system${back}`
}

/* Used in second step for Multiple tags */
session.merge(request, {
selectedLicence: [],
Expand All @@ -281,7 +299,7 @@ const getRemoveTags = async (request, h) => {
pageTitle,
form: formHandler.handleFormRequest(request, linkageForms.removeTagsLicenceView), /* Generates deduplicated list */
sessionData: session.get(request),
back: `/monitoring-stations/${request.params.gaugingStationId}/`
back
})
}

Expand Down Expand Up @@ -386,20 +404,35 @@ const getRemoveTagComplete = async (request, h) => {

const postRemoveTagComplete = async (request, h) => {
await helpers.handleRemovePost(request)
return helpers.redirectTo(request, h, '/../')

let monitoringStationUrl = `/monitoring-stations/${request.params.gaugingStationId}/`

if (featureFlags.enableMonitoringStationsView) {
monitoringStationUrl = `/system${monitoringStationUrl}`
}

return h.redirect(monitoringStationUrl)
}

const getSendAlertSelectAlertType = async (request, h) => {
const pageTitle = 'Select the type of alert you need to send'
const caption = await helpers.getCaption(request)

// NOTE: We have updated this just for correctness! Back links are ignored in the legacy UI because of the back link
// high-jacking implemented in client-side JavaScript we send to the browser.
let back = `/monitoring-stations/${request.params.gaugingStationId}/`

if (featureFlags.enableMonitoringStationsView) {
back = `/system${back}`
}

return h.view('nunjucks/form', {
...request.view,
caption,
pageTitle,
sessionData: session.get(request),
form: formHandler.handleFormRequest(request, linkageForms.sendingAlertType),
back: `/monitoring-stations/${request.params.gaugingStationId}`
back
})
}

Expand Down Expand Up @@ -617,9 +650,15 @@ const getSendAlertCheck = async (request, h) => {
const pageTitle = 'Check the alert for each licence and send'
const caption = await helpers.getCaption(request)

let monitoringStationUrl = `/monitoring-stations/${request.params.gaugingStationId}/`

if (featureFlags.enableMonitoringStationsView) {
monitoringStationUrl = `/system${monitoringStationUrl}`
}

const { notificationEventId } = session.get(request)
if (!notificationEventId) {
return h.redirect(`/monitoring-stations/${request.params.gaugingStationId}`)
return h.redirect(monitoringStationUrl)
}
const event = await services.water.events.findOne(notificationEventId)
const { data: notifications } = await services.water.notifications.getNotificationMessages(notificationEventId)
Expand Down Expand Up @@ -669,9 +708,15 @@ const getSendAlertConfirm = async (request, h) => {
const pageTitle = 'Check the alert for each licence and send'
const caption = await helpers.getCaption(request)

let monitoringStationUrl = `/monitoring-stations/${request.params.gaugingStationId}/`

if (featureFlags.enableMonitoringStationsView) {
monitoringStationUrl = `/system${monitoringStationUrl}`
}

const { notificationEventId } = await session.get(request)
if (!notificationEventId) {
return h.redirect(`/monitoring-stations/${request.params.gaugingStationId}`)
return h.redirect(monitoringStationUrl)
}

const event = await services.water.events.findOne(notificationEventId)
Expand All @@ -683,13 +728,14 @@ const getSendAlertConfirm = async (request, h) => {
logger.warn(e)
}
session.clear(request)

return h.view('nunjucks/gauging-stations/confirm-sending-successful', {
...request.view,
caption,
pageTitle,
recipientCount: event.data.metadata.recipients,
notificationsReportUrl: '/notifications/report',
monitoringStationUrl: `/monitoring-stations/${request.params.gaugingStationId}`
monitoringStationUrl
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}) }}

<p class="govuk-body">
<a class="govuk-link" href="/monitoring-stations/{{ gaugingStationId }}/">Return to monitoring station</a>
<a class="govuk-link" href="{{ monitoringStationUrl }}">Return to monitoring station</a>
</p>

<p class="govuk-body">or</p>
Expand Down
14 changes: 7 additions & 7 deletions test/internal/modules/agreements/controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ experiment('internal/modules/agreements/controller', () => {

test('has the correct back link', () => {
const [, view] = h.view.lastCall.args
expect(view.back).to.equal('/licences/test-licence-id#charge')
expect(view.back).to.equal('/system/licences/test-licence-id/set-up')
})

test('has the correct verb for the warning message', () => {
Expand Down Expand Up @@ -128,7 +128,7 @@ experiment('internal/modules/agreements/controller', () => {

test('redirects back to the licence page', () => {
const [redirectPath] = h.redirect.lastCall.args
expect(redirectPath).to.equal('/licences/test-licence-id#charge')
expect(redirectPath).to.equal('/system/licences/test-licence-id/set-up')
})

experiment('when an error occurs', () => {
Expand All @@ -141,7 +141,7 @@ experiment('internal/modules/agreements/controller', () => {

test('redirects back to licence page', () => {
const [redirectPath] = h.redirect.lastCall.args
expect(redirectPath).to.equal('/licences/test-licence-id#charge')
expect(redirectPath).to.equal('/system/licences/test-licence-id/set-up')
})
})
})
Expand Down Expand Up @@ -169,7 +169,7 @@ experiment('internal/modules/agreements/controller', () => {

test('has the correct back link', () => {
const [, view] = h.view.lastCall.args
expect(view.back).to.equal('/licences/test-licence-id#charge')
expect(view.back).to.equal('/system/licences/test-licence-id/set-up')
})

test('contains the agreement', () => {
Expand Down Expand Up @@ -284,7 +284,7 @@ experiment('internal/modules/agreements/controller', () => {
water.agreements.endAgreement.resolves()
})
test('redirects the client', () => {
expect(h.redirect.calledWith('/licences/test-licence-id#charge')).to.be.true()
expect(h.redirect.calledWith('/system/licences/test-licence-id/set-up')).to.be.true()
})
})
})
Expand Down Expand Up @@ -352,7 +352,7 @@ experiment('internal/modules/agreements/controller', () => {

test('sets the correct back link in the view', async () => {
const [, { back }] = h.view.lastCall.args
expect(back).to.equal(`/licences/${licenceId}#charge`)
expect(back).to.equal(`/system/licences/${licenceId}/set-up`)
})

test('defines a form', async () => {
Expand Down Expand Up @@ -650,7 +650,7 @@ experiment('internal/modules/agreements/controller', () => {

test('redirects back to licence page', () => {
const [redirectPath] = h.redirect.lastCall.args
expect(redirectPath).to.equal(`/licences/${licenceId}#charge`)
expect(redirectPath).to.equal(`/system/licences/${licenceId}/set-up`)
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ experiment('internal/modules/charge-information/controller', () => {

test('sets a back link', async () => {
const { back } = h.view.lastCall.args[1]
expect(back).to.equal('/licences/test-licence-id#charge')
expect(back).to.equal('/system/licences/test-licence-id/set-up')
})

test('has the page title', async () => {
Expand Down Expand Up @@ -1143,7 +1143,7 @@ experiment('internal/modules/charge-information/controller', () => {

test('the user is redirected to the expected page', async () => {
expect(h.redirect.calledWith(
'/licences/test-licence-id#charge'
'/system/licences/test-licence-id/set-up'
)).to.be.true()
})
})
Expand All @@ -1166,7 +1166,7 @@ experiment('internal/modules/charge-information/controller', () => {

test('the user is redirected to the expected page', async () => {
expect(h.redirect.calledWith(
'/licences/test-licence-id#charge'
'/system/licences/test-licence-id/set-up'
)).to.be.true()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ experiment('internal/modules/charge-information/controller', () => {
request.query = { start: 1 }
await controller.getNonChargeableReason(request, h)
const { back } = h.view.lastCall.args[1]
expect(back).to.equal('/licences/test-licence-id#charge')
expect(back).to.equal('/system/licences/test-licence-id/set-up')
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const createRequest = () => ({
clearDraftChargeInformation: sandbox.stub()
})

const licencePageUrl = '/licences/test-licence-id#charge'
const licencePageUrl = '/system/licences/test-licence-id/set-up'

experiment('internal/modules/charge-information/controllers/view-charge-information', () => {
let request, h
Expand Down
2 changes: 1 addition & 1 deletion test/internal/modules/returns/controllers/view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ experiment('internal view controller', () => {
expect(view.data.metadata).to.equal(returnData.metadata)
expect(view.lines).to.equal([{ test: 'lines' }])
expect(view.documentHeader).to.equal({ documentHeader: 'test-doc-header' })
expect(view.links.licence).to.equal('/licences/test-licence-id')
expect(view.links.licence).to.equal('/system/licences/test-licence-id/summary')
})

test('Boom error is thrown if !canView', async () => {
Expand Down

0 comments on commit d025eb4

Please sign in to comment.