-
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.
Fix duplicate purposes in return reqs. set up (#1180)
https://eaflood.atlassian.net/browse/WATER-4592 > Part of the return requirements set up work During the return requirements set up journey, users need to select at least one purpose for each return requirement they are setting up. The purposes they can choose from are only those linked to the current version of the licence. The issue found is that if a licence is linked to a purpose and then to a point, then the same purpose again but to a different point (perhaps because it has condition or different abstraction properties), it causes our logic to return the same purpose twice. More if things are really complicated! This change fixes it so that the user only sees a distinct list of applicable purposes on the 'Select the purpose for the requirements for returns' page.
- Loading branch information
1 parent
1fe0a7a
commit 0ed4882
Showing
7 changed files
with
89 additions
and
84 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
71 changes: 0 additions & 71 deletions
71
test/services/return-requirements/fetch-licence-purposes.service.test.js
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
test/services/return-requirements/fetch-purposes.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,74 @@ | ||
'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 LicenceVersionHelper = require('../../support/helpers/licence-version.helper.js') | ||
const LicenceVersionPurposeHelper = require('../../support/helpers/licence-version-purpose.helper.js') | ||
const PurposeHelper = require('../../support/helpers/purpose.helper.js') | ||
|
||
// Thing under test | ||
const FetchPurposesService = require('../../../app/services/return-requirements/fetch-purposes.service.js') | ||
|
||
describe('Return Requirements - Fetch Purposes service', () => { | ||
let licenceVersion | ||
let purposes | ||
|
||
beforeEach(async () => { | ||
// Create the initial licenceVersion | ||
licenceVersion = await LicenceVersionHelper.add() | ||
|
||
// Create 3 purposes. Note - we purposefully don't add them in alphabetical order so we can test they get sorted | ||
// by the service | ||
purposes = await Promise.all([ | ||
PurposeHelper.add({ description: 'Large Garden Watering' }), | ||
PurposeHelper.add({ description: 'Heat Pump' }), | ||
PurposeHelper.add({ description: 'Horticultural Watering' }) | ||
]) | ||
|
||
// Create the licenceVersionPurposes. Note - two of them are for the same purpose. This is common in the service | ||
// where, for example, a licence might abstract water from 2 different points for the same purpose, but they were | ||
// set up separately (rather than the licence version purpose being linked to multiple points) because the details | ||
// and/or conditions are different at the 2 points. | ||
const licenceVersionId = licenceVersion.id | ||
|
||
await Promise.all([ | ||
LicenceVersionPurposeHelper.add({ licenceVersionId, purposeId: purposes[0].id }), | ||
LicenceVersionPurposeHelper.add({ licenceVersionId, purposeId: purposes[1].id }), | ||
LicenceVersionPurposeHelper.add({ licenceVersionId, purposeId: purposes[1].id }), | ||
LicenceVersionPurposeHelper.add({ licenceVersionId, purposeId: purposes[2].id }) | ||
]) | ||
}) | ||
|
||
describe('when called with a valid licenceId', () => { | ||
it('fetches the data', async () => { | ||
const result = await FetchPurposesService.go(licenceVersion.licenceId) | ||
|
||
expect(result[0]).to.equal({ | ||
id: purposes[1].id, | ||
description: 'Heat Pump' | ||
}) | ||
expect(result[1]).to.equal({ | ||
id: purposes[2].id, | ||
description: 'Horticultural Watering' | ||
}) | ||
expect(result[2]).to.equal({ | ||
id: purposes[0].id, | ||
description: 'Large Garden Watering' | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when called with an invalid licenceId', () => { | ||
it('returns an empty result', async () => { | ||
const result = await FetchPurposesService.go('5505ca34-270a-4dfb-894c-168c8a4d6e23') | ||
|
||
expect(result).to.be.empty() | ||
}) | ||
}) | ||
}) |
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