mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -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:
parent
786f5429db
commit
a7fccf1bf8
2 changed files with 27 additions and 10 deletions
|
@ -3,11 +3,13 @@ class APIVersionCompatibilityService {
|
||||||
*
|
*
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @param {Function} options.sendEmail - email sending function
|
* @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.fetchHandled - retrives already handled compatibility notifications
|
||||||
* @param {(acceptVersion: String) => Promise<any>} options.saveHandled - persists 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.sendEmail = sendEmail;
|
||||||
|
this.emailTo = emailTo;
|
||||||
this.fetchHandled = fetchHandled;
|
this.fetchHandled = fetchHandled;
|
||||||
this.saveHandled = saveHandled;
|
this.saveHandled = saveHandled;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +21,11 @@ class APIVersionCompatibilityService {
|
||||||
Current Ghost version: ${contentVersion}
|
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);
|
await this.saveHandled(acceptVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ describe('APIVersionCompatibilityService', function () {
|
||||||
|
|
||||||
const compatibilityService = new APIVersionCompatibilityService({
|
const compatibilityService = new APIVersionCompatibilityService({
|
||||||
sendEmail,
|
sendEmail,
|
||||||
|
emailTo: 'test_env@example.com',
|
||||||
fetchHandled,
|
fetchHandled,
|
||||||
saveHandled
|
saveHandled
|
||||||
});
|
});
|
||||||
|
@ -25,8 +26,10 @@ describe('APIVersionCompatibilityService', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(sendEmail.called, true);
|
assert.equal(sendEmail.called, true);
|
||||||
assert.match(sendEmail.args[0][0], /Elaborate Fox integration expected Ghost version: v4.5/);
|
assert.equal(sendEmail.args[0][0].to, 'test_env@example.com');
|
||||||
assert.match(sendEmail.args[0][0], /Current Ghost version: v5.1/);
|
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 () {
|
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({
|
const compatibilityService = new APIVersionCompatibilityService({
|
||||||
sendEmail,
|
sendEmail,
|
||||||
|
emailTo: 'test_env@example.com',
|
||||||
fetchHandled,
|
fetchHandled,
|
||||||
saveHandled
|
saveHandled
|
||||||
});
|
});
|
||||||
|
@ -50,8 +54,10 @@ describe('APIVersionCompatibilityService', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(sendEmail.calledOnce, true);
|
assert.equal(sendEmail.calledOnce, true);
|
||||||
assert.match(sendEmail.args[0][0], /Elaborate Fox integration expected Ghost version: v4.5/);
|
assert.equal(sendEmail.args[0][0].to, 'test_env@example.com');
|
||||||
assert.match(sendEmail.args[0][0], /Current Ghost version: v5.1/);
|
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({
|
await compatibilityService.handleMismatch({
|
||||||
acceptVersion: 'v4.5',
|
acceptVersion: 'v4.5',
|
||||||
|
@ -72,6 +78,7 @@ describe('APIVersionCompatibilityService', function () {
|
||||||
|
|
||||||
const compatibilityService = new APIVersionCompatibilityService({
|
const compatibilityService = new APIVersionCompatibilityService({
|
||||||
sendEmail,
|
sendEmail,
|
||||||
|
emailTo: 'test_env@example.com',
|
||||||
fetchHandled,
|
fetchHandled,
|
||||||
saveHandled
|
saveHandled
|
||||||
});
|
});
|
||||||
|
@ -83,8 +90,10 @@ describe('APIVersionCompatibilityService', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(sendEmail.calledOnce, true);
|
assert.equal(sendEmail.calledOnce, true);
|
||||||
assert.match(sendEmail.args[0][0], /Elaborate Fox integration expected Ghost version: v4.5/);
|
assert.equal(sendEmail.args[0][0].to, 'test_env@example.com');
|
||||||
assert.match(sendEmail.args[0][0], /Current Ghost version: v5.1/);
|
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({
|
await compatibilityService.handleMismatch({
|
||||||
acceptVersion: 'v4.8',
|
acceptVersion: 'v4.8',
|
||||||
|
@ -93,7 +102,9 @@ describe('APIVersionCompatibilityService', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(sendEmail.calledTwice, true);
|
assert.equal(sendEmail.calledTwice, true);
|
||||||
assert.match(sendEmail.args[1][0], /Elaborate Fox integration expected Ghost version: v4.8/);
|
assert.equal(sendEmail.args[0][0].to, 'test_env@example.com');
|
||||||
assert.match(sendEmail.args[1][0], /Current Ghost version: v5.1/);
|
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/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue