0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Fixed email sending

refs https://github.com/TryGhost/Toolbox/issues/292

- The standard sendEmail function used in Ghost accepts three non-optional parameters: to, subject, and html. Have extended the usage with these three required fields
This commit is contained in:
Naz 2022-04-20 15:40:50 +08:00
parent 786f5429db
commit a7fccf1bf8
2 changed files with 27 additions and 10 deletions

View file

@ -3,11 +3,13 @@ class APIVersionCompatibilityService {
*
* @param {Object} options
* @param {Function} options.sendEmail - email sending function
* @param {String} options.emailTo - email address to receive notifications
* @param {(acceptVersion: String) => Promise<any>} options.fetchHandled - retrives already handled compatibility notifications
* @param {(acceptVersion: String) => Promise<any>} options.saveHandled - persists already handled compatibility notifications
*/
constructor({sendEmail, fetchHandled, saveHandled}) {
constructor({sendEmail, emailTo, fetchHandled, saveHandled}) {
this.sendEmail = sendEmail;
this.emailTo = emailTo;
this.fetchHandled = fetchHandled;
this.saveHandled = saveHandled;
}
@ -19,7 +21,11 @@ class APIVersionCompatibilityService {
Current Ghost version: ${contentVersion}
`;
await this.sendEmail(emailTemplate);
await this.sendEmail({
subject: `Ghost has noticed that your ${userAgent} integration is no longer working as expected`,
to: this.emailTo,
html: emailTemplate
});
await this.saveHandled(acceptVersion);
}
}

View file

@ -14,6 +14,7 @@ describe('APIVersionCompatibilityService', function () {
const compatibilityService = new APIVersionCompatibilityService({
sendEmail,
emailTo: 'test_env@example.com',
fetchHandled,
saveHandled
});
@ -25,8 +26,10 @@ describe('APIVersionCompatibilityService', function () {
});
assert.equal(sendEmail.called, true);
assert.match(sendEmail.args[0][0], /Elaborate Fox integration expected Ghost version: v4.5/);
assert.match(sendEmail.args[0][0], /Current Ghost version: v5.1/);
assert.equal(sendEmail.args[0][0].to, 'test_env@example.com');
assert.equal(sendEmail.args[0][0].subject, `Ghost has noticed that your Elaborate Fox integration is no longer working as expected`);
assert.match(sendEmail.args[0][0].html, /Elaborate Fox integration expected Ghost version: v4.5/);
assert.match(sendEmail.args[0][0].html, /Current Ghost version: v5.1/);
});
it('Does NOT send an email to the instance owner when previously handled accept-version header mismatch is detected', async function () {
@ -39,6 +42,7 @@ describe('APIVersionCompatibilityService', function () {
const compatibilityService = new APIVersionCompatibilityService({
sendEmail,
emailTo: 'test_env@example.com',
fetchHandled,
saveHandled
});
@ -50,8 +54,10 @@ describe('APIVersionCompatibilityService', function () {
});
assert.equal(sendEmail.calledOnce, true);
assert.match(sendEmail.args[0][0], /Elaborate Fox integration expected Ghost version: v4.5/);
assert.match(sendEmail.args[0][0], /Current Ghost version: v5.1/);
assert.equal(sendEmail.args[0][0].to, 'test_env@example.com');
assert.equal(sendEmail.args[0][0].subject, `Ghost has noticed that your Elaborate Fox integration is no longer working as expected`);
assert.match(sendEmail.args[0][0].html, /Elaborate Fox integration expected Ghost version: v4.5/);
assert.match(sendEmail.args[0][0].html, /Current Ghost version: v5.1/);
await compatibilityService.handleMismatch({
acceptVersion: 'v4.5',
@ -72,6 +78,7 @@ describe('APIVersionCompatibilityService', function () {
const compatibilityService = new APIVersionCompatibilityService({
sendEmail,
emailTo: 'test_env@example.com',
fetchHandled,
saveHandled
});
@ -83,8 +90,10 @@ describe('APIVersionCompatibilityService', function () {
});
assert.equal(sendEmail.calledOnce, true);
assert.match(sendEmail.args[0][0], /Elaborate Fox integration expected Ghost version: v4.5/);
assert.match(sendEmail.args[0][0], /Current Ghost version: v5.1/);
assert.equal(sendEmail.args[0][0].to, 'test_env@example.com');
assert.equal(sendEmail.args[0][0].subject, `Ghost has noticed that your Elaborate Fox integration is no longer working as expected`);
assert.match(sendEmail.args[0][0].html, /Elaborate Fox integration expected Ghost version: v4.5/);
assert.match(sendEmail.args[0][0].html, /Current Ghost version: v5.1/);
await compatibilityService.handleMismatch({
acceptVersion: 'v4.8',
@ -93,7 +102,9 @@ describe('APIVersionCompatibilityService', function () {
});
assert.equal(sendEmail.calledTwice, true);
assert.match(sendEmail.args[1][0], /Elaborate Fox integration expected Ghost version: v4.8/);
assert.match(sendEmail.args[1][0], /Current Ghost version: v5.1/);
assert.equal(sendEmail.args[0][0].to, 'test_env@example.com');
assert.equal(sendEmail.args[0][0].subject, `Ghost has noticed that your Elaborate Fox integration is no longer working as expected`);
assert.match(sendEmail.args[1][0].html, /Elaborate Fox integration expected Ghost version: v4.8/);
assert.match(sendEmail.args[1][0].html, /Current Ghost version: v5.1/);
});
});