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

Query recorded page editing a return journey #1588

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
9 changes: 9 additions & 0 deletions app/controllers/return-logs-setup.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
* @module ReturnLogsSetupController
*/

const ConfirmationService = require('../services/return-logs/setup/confirmation.service.js')
const InitiateSessionService = require('../services/return-logs/setup/initiate-session.service.js')

async function confirmation(request, h) {
const { sessionId } = request.params
const pageData = await ConfirmationService.go(sessionId)

return h.view('return-logs/setup/confirmation.njk', { ...pageData })
}

async function setup(request, h) {
const { returnLogId } = request.query
const session = await InitiateSessionService.go(returnLogId)
Expand All @@ -15,5 +23,6 @@ async function setup(request, h) {
}

module.exports = {
confirmation,
setup
}
36 changes: 36 additions & 0 deletions app/presenters/return-logs/setup/confirmation.presenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

/**
* Format data for the `/return-log/setup/{sessionId}/confirmation` page
* @module ConfirmationPresenter
*/

/**
* Format data for the `/return-log/setup/{sessionId}/confirmation` page
*
* @param {module:SessionModel} session - The return log setup session instance
*
* @returns {object} page data needed by the view template
*/
function go(session) {
const {
id: sessionId,
data: { licenceId, licenceRef, underQuery, purposes, siteDescription, returnLogId }
} = session

return {
sessionId,
returnLog: {
returnLogId,
purposes,
siteDescription
},
licenceRef,
licenceId,
pageTitle: underQuery ? 'Query recorded' : 'Query resolved'
}
}

module.exports = {
go
}
15 changes: 15 additions & 0 deletions app/routes/return-logs-setup.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ const routes = [
}
}
}
},
{
method: 'GET',
path: '/return-logs/setup/{sessionId}/confirmation',
options: {
handler: ReturnLogsSetupController.confirmation,
app: {
plainOutput: true
},
auth: {
access: {
scope: ['billing']
}
}
}
}
]

Expand Down
34 changes: 34 additions & 0 deletions app/services/return-logs/setup/confirmation.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

/**
* Orchestrates fetching and presenting the data for `/return-logs/setup/{sessionId}/confirmation` page
* @module ConfirmationService
*/

const ConfirmationPresenter = require('../../../presenters/return-logs/setup/confirmation.presenter.js')
const SessionModel = require('../../../models/session.model.js')

/**
* Orchestrates fetching and presenting the data for `/return-logs/setup/{sessionId}/confirmation` page
*
* Supports generating the data needed for the confirmation page in the return log setup journey. It fetches the
* current session record and formats the data needed for the page.
*
* @param {string} sessionId - The UUID of the current session
*
* @returns {Promise<object>} The view data for the confirmation page
*/
async function go(sessionId) {
const session = await SessionModel.query().findById(sessionId)

const formattedData = ConfirmationPresenter.go(session)

return {
activeNavBar: 'search',
...formattedData
}
}

module.exports = {
go
}
26 changes: 26 additions & 0 deletions app/services/return-logs/setup/update-under-query.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

/**
* Updates the under query flag on return logs
* @module UpdateUnderQueryService
*/

const ReturnLogModel = require('../../../models/return-log.model.js')

/**
* Updates the under query flag on a return log
*
* @param {string} returnLogId - The UUID of the return log to update
* @param {boolean} underQuery - The value to update the under query flag to
*/
async function go(returnLogId, underQuery) {
await _updateReturnLog(returnLogId, underQuery)
}

async function _updateReturnLog(returnLogId, underQuery) {
return ReturnLogModel.query().update({ underQuery }).findById(returnLogId)
}

module.exports = {
go
}
24 changes: 24 additions & 0 deletions app/views/return-logs/setup/confirmation.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'layout.njk' %}
{% from "govuk/components/panel/macro.njk" import govukPanel %}

{% block content %}
{% set returnDetails %}
<div data-test="licenceNumber">Licence number <strong>{{ licenceRef }}</strong></div><br>
<div data-test="siteDescription">Site description <strong>{{ returnLog.siteDescription }}</strong></div><br>
<div data-test="purpose">Purpose <strong>{{ returnLog.purposes }}</strong></div>
{% endset %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{{ govukPanel({
titleText: pageTitle,
classes: "govuk-!-margin-bottom-4",
html: returnDetails
}) }}
</div>
</div>

<p class="govuk-body">
<a class="govuk-link" href="/system/licences/{{ licenceId }}/returns">View returns for {{ licenceRef }}</a>
</p>
{% endblock %}
39 changes: 39 additions & 0 deletions test/controllers/return-logs-setup.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { describe, it, before, beforeEach, afterEach } = (exports.lab = Lab.scrip
const { expect } = Code

// Things we need to stub
const ConfirmationService = require('../../app/services/return-logs/setup/confirmation.service.js')
const InitiateSessionService = require('../../app/services/return-logs/setup/initiate-session.service.js')

// For running our service
Expand Down Expand Up @@ -65,4 +66,42 @@ describe('Return Logs Setup controller', () => {
})
})
})

describe('return-logs/setup/{sessionId}/confirmation', () => {
describe('GET', () => {
beforeEach(async () => {
options = {
method: 'GET',
url: '/return-logs/setup/e0c77b74-7326-493d-be5e-0d1ad41594b5/confirmation',
auth: {
strategy: 'session',
credentials: { scope: ['billing'] }
}
}
})

describe('when a request is valid', () => {
beforeEach(async () => {
Sinon.stub(ConfirmationService, 'go').resolves({
sessionId: 'e0c77b74-7326-493d-be5e-0d1ad41594b5',
returnLog: {
returnLogId: 'v1:1:01/01:10046821:2020-01-02:2020-02-01',
purpose: 'Test Purpose',
siteDescription: 'Test Site Description',
licenceReference: '01/01'
},
licenceId: '3154ea03-e232-4c66-a711-a72956b7de61',
pageTitle: 'Query recorded'
})
})

it('returns the page successfully', async () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(200)
expect(response.payload).to.contain('Query recorded')
})
})
})
})
})
69 changes: 69 additions & 0 deletions test/presenters/return-logs/setup/confirmation.presenter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict'

// Test framework dependencies
const Lab = require('@hapi/lab')
const Code = require('@hapi/code')

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

// Thing under test
const ConfirmationPresenter = require('../../../../app/presenters/return-logs/setup/confirmation.presenter.js')

describe('Return Logs Setup - Confirmation presenter', () => {
let session

beforeEach(() => {
session = {
id: '61e07498-f309-4829-96a9-72084a54996d',
data: {
licenceId: '7a12fa8e-b9fe-4567-a66e-592db1642cc9',
licenceRef: '01/01',
returnLogId: 'v1:6:01/01:10059108:2023-04-01:2024-03-31',
underQuery: true,
siteDescription: 'Addington Sandpits',
purposes: 'Mineral Washing'
}
}
})

describe('when provided with a session', () => {
it('correctly presents the data', () => {
const result = ConfirmationPresenter.go(session)

expect(result).to.equal({
sessionId: '61e07498-f309-4829-96a9-72084a54996d',
returnLog: {
returnLogId: 'v1:6:01/01:10059108:2023-04-01:2024-03-31',
purposes: 'Mineral Washing',
siteDescription: 'Addington Sandpits'
},
licenceRef: '01/01',
licenceId: '7a12fa8e-b9fe-4567-a66e-592db1642cc9',
pageTitle: 'Query recorded'
})
})
})

describe('the "pageTitle" property', () => {
describe('when the returnLog is under query', () => {
it('returns a "Query recorded"', () => {
const result = ConfirmationPresenter.go(session)

expect(result.pageTitle).to.equal('Query recorded')
})
})

describe('when the returnLog is not under query', () => {
beforeEach(() => {
session.data.underQuery = false
})

it('returns "Query resolved"', () => {
const result = ConfirmationPresenter.go(session)

expect(result.pageTitle).to.equal('Query resolved')
})
})
})
})
72 changes: 72 additions & 0 deletions test/services/return-logs/setup/confirmation.service.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use strict'

// Test framework dependencies
const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const Sinon = require('sinon')

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

// Test helpers
const SessionHelper = require('../../../support/helpers/session.helper.js')

// Thing under test
const ConfirmationService = require('../../../../app/services/return-logs/setup/confirmation.service.js')

describe('Return Logs Setup - Confirmation service', () => {
let session

before(async () => {
session = await SessionHelper.add({
data: {
licenceId: '736144f1-203d-46bb-9968-5137ae06a7bd',
licenceRef: '01/01',
returnLogId: 'v1:6:01/01:10059108:2023-04-01:2024-03-31',
startDate: new Date('2023-04-01'),
endDate: new Date('2024-03-31'),
returnReference: '10059108',
underQuery: false,
periodStartDay: 1,
periodStartMonth: 1,
periodEndDay: 31,
periodEndMonth: 12,
siteDescription: 'Addington Sandpits',
purposes: 'Mineral Washing',
twoPartTariff: false
},
id: 'd958333a-4acd-4add-9e2b-09e14c6b72f3'
})
})

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

describe('when called', () => {
it('fetches the current setup session record', async () => {
const result = await ConfirmationService.go(session.id)

expect(result.sessionId).to.equal(session.id)
})

it('returns page data for the view', async () => {
const result = await ConfirmationService.go(session.id)

expect(result).to.equal(
{
activeNavBar: 'search',
pageTitle: 'Query resolved',
licenceId: '736144f1-203d-46bb-9968-5137ae06a7bd',
licenceRef: '01/01',
returnLog: {
returnLogId: 'v1:6:01/01:10059108:2023-04-01:2024-03-31',
purposes: 'Mineral Washing',
siteDescription: 'Addington Sandpits'
}
},
{ skip: ['sessionId'] }
)
})
})
})
Loading