-
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.
Sort Notifications recipients (#1665)
https://eaflood.atlassian.net/browse/WATER-4775 This change introduces a sort on the recipients array in the presenter. It sorts by the contacts name. We need to work out the name before we can sort. So we first map the recipients and then sort. This will result in all the recipients being mapped and sorted, with only 25 (the current default pagination per page) of the results being used. We have deemed this acceptable for the sake of simplicity and have accounted for performance concerns.
- Loading branch information
1 parent
fe52ea6
commit 2eb03c5
Showing
4 changed files
with
139 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,11 @@ function recipients() { | |
*/ | ||
function duplicateRecipients() { | ||
const duplicateLicenceRef = generateLicenceRef() | ||
const licenceDuplicateLicenceRef = generateLicenceRef() | ||
|
||
return { | ||
duplicateLicenceHolder: _addDuplicateLicenceHolder(duplicateLicenceRef), | ||
duplicateReturnsTo: _addDuplicateReturnsTo(duplicateLicenceRef), | ||
duplicateLicenceHolder: _addDuplicateLicenceHolder(licenceDuplicateLicenceRef), | ||
duplicateReturnsTo: _addDuplicateReturnsTo(licenceDuplicateLicenceRef), | ||
duplicatePrimaryUser: _addDuplicatePrimaryUser(duplicateLicenceRef), | ||
duplicateReturnsAgent: _addDuplicateReturnsAgent(duplicateLicenceRef) | ||
} | ||
|
@@ -45,7 +47,7 @@ function _addDuplicateLicenceHolder(licenceRef) { | |
function _addDuplicateReturnsTo(licenceRef) { | ||
return { | ||
licence_refs: licenceRef, | ||
contact_type: 'Returns To', | ||
contact_type: 'Returns to', | ||
contact: _contact('4', 'Duplicate Returns to', 'Returns to'), | ||
contact_hash_id: 'b1b355491c7d42778890c545e08797ea' | ||
} | ||
|
@@ -96,7 +98,7 @@ function _addDuplicateReturnsAgent(licenceRef) { | |
contact: null, | ||
contact_hash_id: '2e6918568dfbc1d78e2fbe279fftt990', | ||
contact_type: 'Returns agent', | ||
recipient: '[email protected]' | ||
email: '[email protected]' | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ describe('Notifications Setup - Review presenter', () => { | |
let pagination | ||
let testInput | ||
let testRecipients | ||
let testDuplicateRecipients | ||
|
||
beforeEach(() => { | ||
page = 1 | ||
|
@@ -26,8 +27,12 @@ describe('Notifications Setup - Review presenter', () => { | |
} | ||
|
||
testRecipients = RecipientsFixture.recipients() | ||
// This data is used to ensure the recipients are grouped when they have the same licence ref / name. | ||
// Ignore the fact that these would be considered duplicates elsewhere in the code | ||
// (e.g. contact hash / address being identical) | ||
testDuplicateRecipients = RecipientsFixture.duplicateRecipients() | ||
|
||
testInput = Object.values(testRecipients).map((recipient) => { | ||
testInput = [...Object.values(testRecipients), ...Object.values(testDuplicateRecipients)].map((recipient) => { | ||
return { | ||
...recipient, | ||
// The determine recipients service will add the message_type relevant to the recipient | ||
|
@@ -39,33 +44,28 @@ describe('Notifications Setup - Review presenter', () => { | |
}) | ||
|
||
describe('when provided with "recipients"', () => { | ||
it('correctly presents the data', () => { | ||
it('correctly presents the data (in alphabetical order)', () => { | ||
const result = ReviewPresenter.go(testInput, page, pagination) | ||
|
||
expect(result).to.equal({ | ||
defaultPageSize: 25, | ||
pageTitle: 'Send returns invitations', | ||
recipients: [ | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testRecipients.primaryUser.licence_refs], | ||
method: 'Letter or email - Primary user' | ||
contact: ['Mr H J Duplicate Licence holder', '4', 'Privet Drive', 'Little Whinging', 'Surrey', 'WD25 7LR'], | ||
licences: [testDuplicateRecipients.duplicateLicenceHolder.licence_refs], | ||
method: 'Letter or email - Licence holder' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testRecipients.returnsAgent.licence_refs], | ||
method: 'Letter or email - Returns agent' | ||
contact: ['Mr H J Duplicate Returns to', '4', 'Privet Drive', 'Little Whinging', 'Surrey', 'WD25 7LR'], | ||
licences: [testDuplicateRecipients.duplicateReturnsTo.licence_refs], | ||
method: 'Letter or email - Returns to' | ||
}, | ||
{ | ||
contact: ['Mr H J Licence holder', '1', 'Privet Drive', 'Little Whinging', 'Surrey', 'WD25 7LR'], | ||
licences: [testRecipients.licenceHolder.licence_refs], | ||
method: 'Letter or email - Licence holder' | ||
}, | ||
{ | ||
contact: ['Mr H J Returns to', '2', 'Privet Drive', 'Little Whinging', 'Surrey', 'WD25 7LR'], | ||
licences: [testRecipients.returnsTo.licence_refs], | ||
method: 'Letter or email - Returns to' | ||
}, | ||
{ | ||
contact: [ | ||
'Mr H J Licence holder with multiple licences', | ||
|
@@ -77,9 +77,34 @@ describe('Notifications Setup - Review presenter', () => { | |
], | ||
licences: testRecipients.licenceHolderWithMultipleLicences.licence_refs.split(','), | ||
method: 'Letter or email - Licence holder' | ||
}, | ||
{ | ||
contact: ['Mr H J Returns to', '2', 'Privet Drive', 'Little Whinging', 'Surrey', 'WD25 7LR'], | ||
licences: [testRecipients.returnsTo.licence_refs], | ||
method: 'Letter or email - Returns to' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testRecipients.primaryUser.licence_refs], | ||
method: 'Letter or email - Primary user' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testDuplicateRecipients.duplicatePrimaryUser.licence_refs], | ||
method: 'Letter or email - Primary user' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testRecipients.returnsAgent.licence_refs], | ||
method: 'Letter or email - Returns agent' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testDuplicateRecipients.duplicateReturnsAgent.licence_refs], | ||
method: 'Letter or email - Returns agent' | ||
} | ||
], | ||
recipientsAmount: 5 | ||
recipientsAmount: 9 | ||
}) | ||
}) | ||
|
||
|
@@ -90,25 +115,27 @@ describe('Notifications Setup - Review presenter', () => { | |
|
||
expect(result.recipients).to.equal([ | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testRecipients.primaryUser.licence_refs], | ||
method: 'Letter or email - Primary user' | ||
contact: [ | ||
'Mr H J Duplicate Licence holder', | ||
'4', | ||
'Privet Drive', | ||
'Little Whinging', | ||
'Surrey', | ||
'WD25 7LR' | ||
], | ||
licences: [testDuplicateRecipients.duplicateLicenceHolder.licence_refs], | ||
method: 'Letter or email - Licence holder' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testRecipients.returnsAgent.licence_refs], | ||
method: 'Letter or email - Returns agent' | ||
contact: ['Mr H J Duplicate Returns to', '4', 'Privet Drive', 'Little Whinging', 'Surrey', 'WD25 7LR'], | ||
licences: [testDuplicateRecipients.duplicateReturnsTo.licence_refs], | ||
method: 'Letter or email - Returns to' | ||
}, | ||
{ | ||
contact: ['Mr H J Licence holder', '1', 'Privet Drive', 'Little Whinging', 'Surrey', 'WD25 7LR'], | ||
licences: [testRecipients.licenceHolder.licence_refs], | ||
method: 'Letter or email - Licence holder' | ||
}, | ||
{ | ||
contact: ['Mr H J Returns to', '2', 'Privet Drive', 'Little Whinging', 'Surrey', 'WD25 7LR'], | ||
licences: [testRecipients.returnsTo.licence_refs], | ||
method: 'Letter or email - Returns to' | ||
}, | ||
{ | ||
contact: [ | ||
'Mr H J Licence holder with multiple licences', | ||
|
@@ -120,6 +147,31 @@ describe('Notifications Setup - Review presenter', () => { | |
], | ||
licences: testRecipients.licenceHolderWithMultipleLicences.licence_refs.split(','), | ||
method: 'Letter or email - Licence holder' | ||
}, | ||
{ | ||
contact: ['Mr H J Returns to', '2', 'Privet Drive', 'Little Whinging', 'Surrey', 'WD25 7LR'], | ||
licences: [testRecipients.returnsTo.licence_refs], | ||
method: 'Letter or email - Returns to' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testRecipients.primaryUser.licence_refs], | ||
method: 'Letter or email - Primary user' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testDuplicateRecipients.duplicatePrimaryUser.licence_refs], | ||
method: 'Letter or email - Primary user' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testRecipients.returnsAgent.licence_refs], | ||
method: 'Letter or email - Returns agent' | ||
}, | ||
{ | ||
contact: ['[email protected]'], | ||
licences: [testDuplicateRecipients.duplicateReturnsAgent.licence_refs], | ||
method: 'Letter or email - Returns agent' | ||
} | ||
]) | ||
}) | ||
|
@@ -199,7 +251,7 @@ describe('Notifications Setup - Review presenter', () => { | |
|
||
describe('and there are >= 25 recipients', () => { | ||
beforeEach(() => { | ||
testInput = [...testInput, ...testInput, ...testInput, ...testInput, ...testInput, ...testInput] | ||
testInput = [...testInput, ...testInput, ...testInput] | ||
|
||
pagination = { | ||
numberOfPages: 2 | ||
|
@@ -228,7 +280,7 @@ describe('Notifications Setup - Review presenter', () => { | |
it('returns the remaining recipients', () => { | ||
const result = ReviewPresenter.go(testInput, page, pagination) | ||
|
||
expect(result.recipients.length).to.equal(5) | ||
expect(result.recipients.length).to.equal(2) | ||
}) | ||
|
||
it('returns the updated "pageTitle"', () => { | ||
|
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