mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
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:
parent
5f157efcd9
commit
aeadf8a5e1
@ -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: {
|
||||
|
@ -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
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user