-
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.
Feature notifications setup session (#1574)
https://eaflood.atlassian.net/browse/WATER-4716 As part of the ongoing work to migrate the legacy UI we are replacing the notification journey from the UI and rebuilding in system. This change introduces session initialization to allow the journey to store user answers. This new route notifications/setup is now the target for the water abstraction UI redirect
- Loading branch information
1 parent
3df2c8e
commit 42b9f8c
Showing
5 changed files
with
115 additions
and
6 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
31 changes: 31 additions & 0 deletions
31
app/services/notifications/setup/initiate-session.service.js
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,31 @@ | ||
'use strict' | ||
|
||
/** | ||
* Initiates the session record used for setting up a new ad-hoc returns notification | ||
* @module InitiateSessionService | ||
*/ | ||
|
||
const SessionModel = require('../../../models/session.model.js') | ||
|
||
/** | ||
* Initiates the session record used for setting up a new ad-hoc returns notification | ||
* | ||
* During the setup journey for a new ad-hoc returns notification we temporarily store the data in a `SessionModel` | ||
* instance. It is expected that on each page of the journey the GET will fetch the session record and use it to | ||
* populate the view. | ||
* When the page is submitted the session record will be updated with the next piece of data. | ||
* | ||
* At the end when the journey is complete the data from the session will be used to create the ad-hoc returns | ||
* notification and the session record itself deleted. | ||
* | ||
* @returns {Promise<module:SessionModel>} the newly created session record | ||
*/ | ||
async function go() { | ||
// NOTE: data defaults to {} when a new record is created. But Objection.js throws a 'The query is empty' if we pass | ||
// nothing into `insert()`. | ||
return SessionModel.query().insert({ data: {} }).returning('id') | ||
} | ||
|
||
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
26 changes: 26 additions & 0 deletions
26
test/services/notifications/setup/initiate-session.service.test.js
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,26 @@ | ||
'use strict' | ||
|
||
// Test framework dependencies | ||
const Lab = require('@hapi/lab') | ||
const Code = require('@hapi/code') | ||
|
||
const { describe, it } = (exports.lab = Lab.script()) | ||
const { expect } = Code | ||
|
||
// Test helpers | ||
const SessionModel = require('../../../../app/models/session.model.js') | ||
|
||
// Thing under test | ||
const InitiateSessionService = require('../../../../app/services/notifications/setup/initiate-session.service.js') | ||
|
||
describe('Notifications Setup - Initiate Session service', () => { | ||
describe('when called', () => { | ||
it('creates a new session record with an empty data property', async () => { | ||
const result = await InitiateSessionService.go() | ||
|
||
const matchingSession = await SessionModel.query().findById(result.id) | ||
|
||
expect(matchingSession.data).to.equal({}) | ||
}) | ||
}) | ||
}) |