-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding multiple return requirements to the session (#1014)
* Adding multiple return requirements to the session This PR is focused on allowing users to add another return requirement to the current session once they have reached the check page in the journey. Users will be redirected to the purpose page for the new requirement.
- Loading branch information
Showing
9 changed files
with
249 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
/** | ||
* Orchestrates adding an empty object to the requirements array in the session | ||
* @module AddService | ||
*/ | ||
|
||
const SessionModel = require('../../models/session.model.js') | ||
|
||
/** | ||
* Orchestrates adding an empty object to the requirements array in the session | ||
* | ||
* Supports adding another object to the requirements array in the session when a user hits the 'Add another | ||
* requirement' button. | ||
* | ||
* @param {string} sessionId - The UUID of the current session | ||
* | ||
* @returns {number} - The index of the new requirement. Needed by the setup pages so they know which requirement to | ||
* display and update | ||
*/ | ||
async function go (sessionId) { | ||
const session = await SessionModel.query().findById(sessionId) | ||
|
||
await _save(session) | ||
|
||
return session.requirements.length - 1 | ||
} | ||
|
||
async function _save (session) { | ||
session.requirements.push({}) | ||
|
||
session.checkPageVisited = false | ||
|
||
return session.$update() | ||
} | ||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'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 | ||
|
||
// Test helpers | ||
const DatabaseSupport = require('../../support/database.js') | ||
const SessionHelper = require('../../support/helpers/session.helper.js') | ||
|
||
// Thing under test | ||
const AddService = require('../../../app/services/return-requirements/add.service.js') | ||
|
||
describe('Return Requirements - Add service', () => { | ||
let session | ||
|
||
beforeEach(async () => { | ||
await DatabaseSupport.clean() | ||
|
||
session = await SessionHelper.add({ | ||
data: { | ||
checkPageVisited: false, | ||
licence: { | ||
id: '8b7f78ba-f3ad-4cb6-a058-78abc4d1383d', | ||
currentVersionStartDate: '2023-01-01T00:00:00.000Z', | ||
endDate: null, | ||
licenceRef: '01/ABC', | ||
licenceHolder: 'Turbo Kid', | ||
startDate: '2022-04-01T00:00:00.000Z' | ||
}, | ||
journey: 'returns-required', | ||
requirements: [{}], | ||
startDateOptions: 'licenceStartDate', | ||
reason: 'major-change' | ||
} | ||
}) | ||
}) | ||
|
||
describe('when called', () => { | ||
it('adds another empty object to the requirement array in the current setup session record', async () => { | ||
await AddService.go(session.id) | ||
|
||
const refreshedSession = await session.$query() | ||
|
||
expect(refreshedSession.data.requirements.length).to.equal(2) | ||
expect(refreshedSession.data.requirements).to.equal([{}, {}]) | ||
}) | ||
|
||
it('returns the index of the new requirement', async () => { | ||
const result = await AddService.go(session.id) | ||
|
||
expect(result).to.equal(1) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.