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

Replay submitted data with a validation error #956

Merged
merged 8 commits into from
Apr 30, 2024
13 changes: 11 additions & 2 deletions app/services/return-requirements/submit-start-date.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ async function go (sessionId, payload) {
}
}

const formattedData = StartDatePresenter.go(session, payload)
const submittedSessionData = _submittedSessionData(session, payload)

return {
activeNavBar: 'search',
checkYourAnswersVisited: session.data.checkYourAnswersVisited,
error: validationResult,
journey: session.data.journey,
pageTitle: 'Select the start date for the return requirement',
...formattedData
...submittedSessionData
}
}

Expand All @@ -66,6 +66,15 @@ async function _save (session, payload) {
return session.$query().patch({ data: currentData })
}

function _submittedSessionData (session, payload) {
session.data.startDateDay = payload['start-date-day'] ? payload['start-date-day'] : null
session.data.startDateMonth = payload['start-date-month'] ? payload['start-date-month'] : null
session.data.startDateYear = payload['start-date-year'] ? payload['start-date-year'] : null
session.data.startDateOptions = payload['start-date-options'] ? payload['start-date-options'] : null

return StartDatePresenter.go(session, payload)
}

function _validate (payload, licenceStartDate, licenceEndDate) {
const validation = StartDateValidator.go(payload, licenceStartDate, licenceEndDate)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ describe('Submit Start Date service', () => {
licenceId: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d',
licenceRef: '01/ABC',
licenceVersionStartDate: '1 January 2023',
anotherStartDateDay: null,
anotherStartDateMonth: null,
anotherStartDateYear: null,
anotherStartDateSelected: false,
anotherStartDateDay: 'a',
anotherStartDateMonth: 'b',
anotherStartDateYear: 'c',
anotherStartDateSelected: true,
licenceStartDateSelected: false
}, { skip: ['id', 'error'] })
})
Expand Down
Loading