diff --git a/app/presenters/return-requirements/existing.presenter.js b/app/presenters/return-requirements/existing.presenter.js
index 266c5c6db5..1d6c299f80 100644
--- a/app/presenters/return-requirements/existing.presenter.js
+++ b/app/presenters/return-requirements/existing.presenter.js
@@ -5,6 +5,9 @@
* @module ExistingPresenter
*/
+const { formatLongDate } = require('../base.presenter.js')
+const { returnRequirementReasons } = require('../../lib/static-lookups.lib.js')
+
/**
* Formats data for the `/return-requirements/{sessionId}/existing` page
*
@@ -16,11 +19,28 @@ function go (session) {
const { id: sessionId, licence } = session
return {
+ existingOptions: _existingOptions(licence.returnVersions),
licenceRef: licence.licenceRef,
sessionId
}
}
+function _existingOptions (returnVersions) {
+ return returnVersions.map((returnVersion) => {
+ const { id, reason, startDate } = returnVersion
+
+ // NOTE: because the session data is stored in a JSONB field when we get the instance from the DB the date values
+ // are in JS Date format (string). So, we have to convert it to a date before calling `formatLongDate()`
+ const dateObj = new Date(startDate)
+ const formattedStartDate = formatLongDate(dateObj)
+
+ return {
+ value: id,
+ text: reason ? `${formattedStartDate} - ${returnRequirementReasons[reason]}` : formattedStartDate
+ }
+ })
+}
+
module.exports = {
go
}
diff --git a/app/views/return-requirements/existing.njk b/app/views/return-requirements/existing.njk
index 3c7556e0d9..d19070c047 100644
--- a/app/views/return-requirements/existing.njk
+++ b/app/views/return-requirements/existing.njk
@@ -1,6 +1,7 @@
{% extends 'layout.njk' %}
{% from "govuk/components/back-link/macro.njk" import govukBackLink %}
{% from "govuk/components/button/macro.njk" import govukButton %}
+{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% block breadcrumbs %}
{# Back link #}
@@ -14,14 +15,32 @@
{% block content %}
{# Main heading #}
+ {% set radioItems = [] %}
+ {% for existingOption in existingOptions %}
+ {% set radioItem = {
+ value: existingOption.value,
+ text: existingOption.text
+ } %}
+
+ {% set radioItems = (radioItems.push(radioItem), radioItems) %}
+ {% endfor %}
+
- Licence {{ licenceRef }}
-
{{ pageTitle }}
-
+
+
+
{% endblock %}
diff --git a/test/presenters/return-requirements/existing.presenter.test.js b/test/presenters/return-requirements/existing.presenter.test.js
index 4dd18ddbd3..6b8e9dd024 100644
--- a/test/presenters/return-requirements/existing.presenter.test.js
+++ b/test/presenters/return-requirements/existing.presenter.test.js
@@ -41,9 +41,39 @@ describe('Return Requirements - Existing presenter', () => {
const result = ExistingPresenter.go(session)
expect(result).to.equal({
+ existingOptions: [{ value: '60b5d10d-1372-4fb2-b222-bfac81da69ab', text: '1 January 2023' }],
licenceRef: '01/ABC',
sessionId: '61e07498-f309-4829-96a9-72084a54996d'
})
})
})
+
+ describe('the "existingOptions" property', () => {
+ describe('when the return versions do not contain a "reason"', () => {
+ it('returns the version ID as the option value and just the start date as the option text', () => {
+ const result = ExistingPresenter.go(session)
+
+ expect(result.existingOptions).to.equal([
+ { value: '60b5d10d-1372-4fb2-b222-bfac81da69ab', text: '1 January 2023' }
+ ])
+ })
+ })
+
+ describe('when the return versions contain a "reason"', () => {
+ beforeEach(() => {
+ session.licence.returnVersions.unshift({
+ id: '22ecef19-3a13-44a0-a55e-8f4d34dd59a5', reason: 'major-change', startDate: '2024-05-07T00:00:00.000Z'
+ })
+ })
+
+ it('returns the version ID as the option value and the start date and reason as the option text', () => {
+ const result = ExistingPresenter.go(session)
+
+ expect(result.existingOptions).to.equal([
+ { value: '22ecef19-3a13-44a0-a55e-8f4d34dd59a5', text: '7 May 2024 - Major change' },
+ { value: '60b5d10d-1372-4fb2-b222-bfac81da69ab', text: '1 January 2023' }
+ ])
+ })
+ })
+ })
})
diff --git a/test/services/return-requirements/existing.service.test.js b/test/services/return-requirements/existing.service.test.js
index ac848d05f5..fd543ee721 100644
--- a/test/services/return-requirements/existing.service.test.js
+++ b/test/services/return-requirements/existing.service.test.js
@@ -55,6 +55,7 @@ describe('Return Requirements - Existing service', () => {
expect(result).to.equal({
activeNavBar: 'search',
pageTitle: 'Select an existing return requirement from',
+ existingOptions: [{ value: '60b5d10d-1372-4fb2-b222-bfac81da69ab', text: '1 January 2023' }],
licenceRef: '01/ABC'
}, { skip: ['sessionId'] })
})