Added email alert trigger for free member signup

refs TryGhost/Team#1826

- fires email alert on free member creation after they finish signing up via checkout link
This commit is contained in:
Rishabh 2022-08-25 12:58:26 +05:30 committed by Rishabh Garg
parent 5f157efcd9
commit aeadf8a5e1
2 changed files with 48 additions and 3 deletions

View File

@ -44,7 +44,7 @@ describe('sendMagicLink', function () {
// Get data
const data = await membersService.api.getTokenDataFromMagicLinkToken(token);
should(data).match({
email,
attribution: {
@ -55,6 +55,42 @@ describe('sendMagicLink', function () {
});
});
it('triggers email alert for free member signup', async function () {
const email = 'newly-created-user-magic-link-test@test.com';
await membersAgent.post('/api/send-magic-link')
.body({
email,
emailType: 'signup'
})
.expectEmptyBody()
.expectStatus(201);
// Check email is sent
const mail = mockManager.assert.sentEmail({
to: email,
subject: /Complete your sign up to Ghost!/
});
// Get link from email
const [url] = mail.text.match(/https?:\/\/[^\s]+/);
const parsed = new URL(url);
const token = parsed.searchParams.get('token');
// Get member data from token
const data = await membersService.api.getMemberDataFromMagicLinkToken(token);
// Check member alert is sent to site owners
mockManager.assert.sentEmail({
to: 'jbloggs@example.com',
subject: /🥳 Free member signup: newly-created-user-magic-link-test@test.com/
});
// Check member data is returned
should(data).match({
email
});
});
it('Converts the urlHistory to the attribution and stores it in the token', async function () {
const email = 'newly-created-user-magic-link-test-2@test.com';
await membersAgent.post('/api/send-magic-link')
@ -84,7 +120,7 @@ describe('sendMagicLink', function () {
// Get data
const data = await membersService.api.getTokenDataFromMagicLinkToken(token);
should(data).match({
email,
attribution: {

View File

@ -60,6 +60,7 @@ module.exports = function MembersAPI({
},
stripeAPIService,
offersAPI,
staffService,
labsService,
newslettersService,
memberAttributionService
@ -85,6 +86,7 @@ module.exports = function MembersAPI({
stripeAPIService,
tokenService,
newslettersService,
staffService,
labsService,
productRepository,
Member,
@ -149,6 +151,7 @@ module.exports = function MembersAPI({
productRepository,
StripePrice,
tokenService,
staffService,
sendEmailWithMagicLink
});
@ -218,6 +221,12 @@ module.exports = function MembersAPI({
return member;
}
const newMember = await users.create({name, email, labels, newsletters, attribution});
// Notify staff users of new free member signup
if (labsService.isSet('emailAlerts')) {
await staffService.notifyFreeMemberSignup(newMember.toJSON());
}
await MemberLoginEvent.add({member_id: newMember.id});
return getMemberIdentityData(email);
}
@ -324,7 +333,7 @@ module.exports = function MembersAPI({
memberBREADService,
events: eventRepository,
productRepository,
// Test helpers
getTokenDataFromMagicLinkToken
};