-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #759 from HDRUK/release-preprod/v2.9.0
Release preprod/v2.9.0
- Loading branch information
Showing
13 changed files
with
480 additions
and
146 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -104,7 +104,7 @@ module.exports = { | |
|
||
// 15. Prepare to send email if a new message has been created | ||
if (messageType === 'message') { | ||
let optIn, subscribedEmails; | ||
let optIn, subscribedEmails, messageCreatorRecipient; | ||
// 16. Find recipients who have opted in to email updates and exclude the requesting user | ||
let messageRecipients = await UserModel.find({ _id: { $in: topicObj.recipients } }); | ||
|
||
|
@@ -125,10 +125,21 @@ module.exports = { | |
); | ||
if (!_.isEmpty(subscribedMembersByType)) { | ||
// build cleaner array of memberIds from subscribedMembersByType | ||
const memberIds = [...subscribedMembersByType.map(m => m.memberid.toString()), topicObj.createdBy.toString()]; | ||
// returns array of objects [{email: '[email protected] '}] for members in subscribed emails users is list of full user object | ||
const { memberEmails } = teamController.getMemberDetails([...memberIds], [...messageRecipients]); | ||
messageRecipients = [...teamNotificationEmails, ...memberEmails]; | ||
if (topicObj.topicMessages !== undefined) { | ||
const memberIds = [...subscribedMembersByType.map(m => m.memberid.toString()), ...topicObj.createdBy._id.toString()]; | ||
// returns array of objects [{email: '[email protected] '}] for members in subscribed emails users is list of full user object | ||
const { memberEmails } = teamController.getMemberDetails([...memberIds], [...messageRecipients]); | ||
messageRecipients = [...teamNotificationEmails, ...memberEmails]; | ||
} else { | ||
const memberIds = [...subscribedMembersByType.map(m => m.memberid.toString())].filter(ele => ele !== topicObj.createdBy.toString()); | ||
const creatorObjectId = topicObj.createdBy.toString(); | ||
// returns array of objects [{email: '[email protected] '}] for members in subscribed emails users is list of full user object | ||
const { memberEmails } = teamController.getMemberDetails([...memberIds], [...messageRecipients]); | ||
const creatorEmail = await UserModel.findById(creatorObjectId); | ||
messageCreatorRecipient = [{ email: creatorEmail.email}]; | ||
messageRecipients = [...teamNotificationEmails, ...memberEmails]; | ||
} | ||
|
||
} else { | ||
// only if not membersByType but has a team email setup | ||
messageRecipients = [...messageRecipients, ...teamNotificationEmails]; | ||
|
@@ -155,6 +166,18 @@ module.exports = { | |
html, | ||
false | ||
); | ||
|
||
if (messageCreatorRecipient) { | ||
let htmlCreator = emailGenerator.generateMessageCreatorNotification(options); | ||
|
||
emailGenerator.sendEmail( | ||
messageCreatorRecipient, | ||
constants.hdrukEmail, | ||
`You have received a new message on the HDR UK Innovation Gateway`, | ||
htmlCreator, | ||
false | ||
); | ||
} | ||
} | ||
// 19. Return successful response with message data | ||
const messageObj = message.toObject(); | ||
|
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
35 changes: 0 additions & 35 deletions
35
src/resources/user/__tests__/getCollaboratorsCohorts.test.js
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/resources/utilities/__tests__/emailGenerator.util.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,44 @@ | ||
import emailGenerator from '../emailGenerator.util'; | ||
|
||
describe('Email generator utility functions', () => { | ||
describe('_generateMetadataOnboardingRejected', () => { | ||
let isFederated; | ||
|
||
it('SHOULD include federated warning if isFederated is true', async () => { | ||
isFederated = true; | ||
|
||
const emailBody = emailGenerator.generateMetadataOnboardingRejected({ isFederated }); | ||
|
||
// Federated warning should be present if dataset is from a federated publisher | ||
expect(emailBody.includes('Do not apply these changes directly to the Gateway')).toBe(true); | ||
}); | ||
|
||
it('SHOULD NOT include federated warning if isFederated is false', async () => { | ||
isFederated = false; | ||
|
||
const emailBody = emailGenerator.generateMetadataOnboardingRejected({ isFederated }); | ||
|
||
// Federated warning should not be present if dataset is not from a federated publisher | ||
expect(emailBody.includes('Do not apply these changes directly to the Gateway')).toBe(false); | ||
}); | ||
}); | ||
describe('_getRecipients', () => { | ||
const mockRecipients = [ | ||
{ email: '[email protected]' }, | ||
{ email: '[email protected]' }, | ||
{ email: '[email protected]' }, | ||
{ email: '[email protected]' }, | ||
]; | ||
it('Should remove duplicaties for production', async () => { | ||
const recipients = emailGenerator.getRecipients(mockRecipients, 'production', '[email protected]'); | ||
expect(recipients.length).toBe(3); | ||
expect(recipients).toEqual([{ email: '[email protected]' }, { email: '[email protected]' }, { email: '[email protected]' }]); | ||
}); | ||
|
||
it('Should replace recipients non production environtment to generic email', async () => { | ||
const recipients = emailGenerator.getRecipients(mockRecipients, undefined, '[email protected]'); | ||
expect(recipients.length).toBe(1); | ||
expect(recipients).toEqual([{ 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
Oops, something went wrong.