Added [test] prefix to test emails (#19431)

fixes GRO-157

- the [TEST] prefix was removed unintentionally during the rewrite of
the email sending service
This commit is contained in:
Sag 2024-01-03 13:08:56 -03:00 committed by GitHub
parent d89dace67f
commit 21397a4518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 4 deletions

View File

@ -167,8 +167,9 @@ class EmailRenderer {
this.#models = models;
}
getSubject(post) {
return post.related('posts_meta')?.get('email_subject') || post.get('title');
getSubject(post, isTestEmail = false) {
const subject = post.related('posts_meta')?.get('email_subject') || post.get('title');
return isTestEmail ? `[TEST] ${subject}` : subject;
}
#getRawFromAddress(post, newsletter) {

View File

@ -301,7 +301,8 @@ class EmailService {
emailId: null
}, {
clickTrackingEnabled: false,
openTrackingEnabled: false
openTrackingEnabled: false,
isTestEmail: true
});
}
}

View File

@ -88,6 +88,7 @@ class SendingService {
*/
async send({post, newsletter, segment, members, emailId}, options) {
const cacheId = emailId + '-' + (segment ?? 'null');
const isTestEmail = options.isTestEmail ?? false;
/**
* @type {EmailBody | null}
@ -114,7 +115,7 @@ class SendingService {
const recipients = this.buildRecipients(members, emailBody.replacements);
return await this.#emailProvider.send({
subject: this.#emailRenderer.getSubject(post),
subject: this.#emailRenderer.getSubject(post, isTestEmail),
from: this.#emailRenderer.getFromAddress(post, newsletter),
replyTo: this.#emailRenderer.getReplyToAddress(post, newsletter) ?? undefined,
html: emailBody.html,

View File

@ -662,6 +662,18 @@ describe('Email renderer', function () {
let response = emailRenderer.getSubject(post);
response.should.equal('Sample Post');
});
it('adds [TEST] prefix for test emails', function () {
const post = createModel({
posts_meta: createModel({
email_subject: ''
}),
title: 'Sample Post',
loaded: ['posts_meta']
});
let response = emailRenderer.getSubject(post, true);
response.should.equal('[TEST] Sample Post');
});
});
describe('getFromAddress', function () {

View File

@ -428,8 +428,10 @@ describe('Email Service', function () {
await service.sendTestEmail(post, post.get('newsletter'), null, ['example@example.com']);
sinon.assert.calledOnce(sendingService.send);
const members = sendingService.send.firstCall.args[0].members;
const options = sendingService.send.firstCall.args[1];
assert.equal(members.length, 1);
assert.equal(members[0].email, 'example@example.com');
assert.equal(options.isTestEmail, true);
});
});
});