mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 11:55:01 +03:00
🐛 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:
parent
6f0d1b0ff9
commit
0e8d13bdde
@ -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;
|
||||
}, {});
|
||||
|
@ -142,7 +142,7 @@ class SendingService {
|
||||
return {
|
||||
id: def.id,
|
||||
token: def.token,
|
||||
value: def.getValue(member)
|
||||
value: def.getValue(member) || ''
|
||||
};
|
||||
})
|
||||
};
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user