🐛 Fixed email replacements without fallback

fixes https://github.com/TryGhost/Team/issues/2557

When a member doen't have a name, and the first_name replacement doesn't have a fallback, we did show %recipient.first_name% instead of an empty string.
This commit is contained in:
Simon Backx 2023-02-13 15:49:43 +01:00
parent 6f0d1b0ff9
commit 0e8d13bdde
3 changed files with 57 additions and 4 deletions

View File

@ -50,9 +50,6 @@ class MailgunEmailProvider {
recipientData = replacements.reduce((acc, replacement) => {
const {id, value} = replacement;
if (!acc[id]) {
acc[id] = {};
}
acc[id] = value;
return acc;
}, {});

View File

@ -142,7 +142,7 @@ class SendingService {
return {
id: def.id,
token: def.token,
value: def.getValue(member)
value: def.getValue(member) || ''
};
})
};

View File

@ -103,6 +103,62 @@ describe('Sending service', function () {
));
});
it('defaults to empty string if replacement returns undefined', async function () {
const sendingService = new SendingService({
emailRenderer,
emailProvider
});
const response = await sendingService.send({
post: {},
newsletter: {},
segment: null,
emailId: '123',
members: [
{
email: 'member@example.com',
name: undefined
}
]
}, {
clickTrackingEnabled: true,
openTrackingEnabled: true
});
assert.equal(response.id, 'provider-123');
sinon.assert.calledOnce(sendStub);
assert(sendStub.calledWith(
{
subject: 'Hi',
from: 'ghost@example.com',
replyTo: 'ghost+reply@example.com',
html: '<html><body>Hi {{name}}</body></html>',
plaintext: 'Hi',
emailId: '123',
replacementDefinitions: [
{
id: 'name',
token: '{{name}}',
getValue: sinon.match.func
}
],
recipients: [
{
email: 'member@example.com',
replacements: [{
id: 'name',
token: '{{name}}',
value: ''
}]
}
]
},
{
clickTrackingEnabled: true,
openTrackingEnabled: true
}
));
});
it('supports cache', async function () {
const emailBodyCache = new EmailBodyCache();
const sendingService = new SendingService({