mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Support custom subject line with getSubject option
no-issue
This commit is contained in:
parent
1e8bac111f
commit
2de53f8571
2 changed files with 18 additions and 0 deletions
|
@ -42,6 +42,19 @@ function defaultGetHTML(url, type, email) {
|
|||
return `<a href="${url}">Click here to ${msg}</a> This msg was sent to ${email}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* defaultGetSubject
|
||||
*
|
||||
* @param {string} type - The type of email to send e.g. signin, signup
|
||||
* @returns {string} subject - The subject of an email to send
|
||||
*/
|
||||
function defaultGetSubject(type) {
|
||||
if (type === 'signup') {
|
||||
return `Signup!`;
|
||||
}
|
||||
return `Signin!`;
|
||||
}
|
||||
|
||||
/**
|
||||
* MagicLink
|
||||
* @constructor
|
||||
|
@ -53,6 +66,7 @@ function defaultGetHTML(url, type, email) {
|
|||
* @param {(token: JSONWebToken, type: string) => URL} options.getSigninURL
|
||||
* @param {typeof defaultGetText} [options.getText]
|
||||
* @param {typeof defaultGetHTML} [options.getHTML]
|
||||
* @param {typeof defaultGetSubject} [options.getSubject]
|
||||
*/
|
||||
function MagicLink(options) {
|
||||
if (!options || !options.transporter || !options.publicKey || !options.privateKey || !options.getSigninURL) {
|
||||
|
@ -64,6 +78,7 @@ function MagicLink(options) {
|
|||
this.getSigninURL = options.getSigninURL;
|
||||
this.getText = options.getText || defaultGetText;
|
||||
this.getHTML = options.getHTML || defaultGetHTML;
|
||||
this.getSubject = options.getSubject || defaultGetSubject;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,6 +107,7 @@ MagicLink.prototype.sendMagicLink = async function sendMagicLink(options) {
|
|||
|
||||
const info = await this.transporter.sendMail({
|
||||
to: options.email,
|
||||
subject: this.getSubject(type),
|
||||
text: this.getText(url, type, options.email),
|
||||
html: this.getHTML(url, type, options.email)
|
||||
});
|
||||
|
|
|
@ -29,6 +29,7 @@ describe('MagicLink', function () {
|
|||
getSigninURL: sandbox.stub().returns('FAKEURL'),
|
||||
getText: sandbox.stub().returns('SOMETEXT'),
|
||||
getHTML: sandbox.stub().returns('SOMEHTML'),
|
||||
getSubject: sandbox.stub().returns('SOMESUBJECT'),
|
||||
transporter: {
|
||||
sendMail: sandbox.stub().resolves()
|
||||
}
|
||||
|
@ -49,6 +50,7 @@ describe('MagicLink', function () {
|
|||
|
||||
should.ok(options.transporter.sendMail.calledOnce);
|
||||
should.equal(options.transporter.sendMail.firstCall.args[0].to, args.email);
|
||||
should.equal(options.transporter.sendMail.firstCall.args[0].subject, options.getSubject.firstCall.returnValue);
|
||||
should.equal(options.transporter.sendMail.firstCall.args[0].text, options.getText.firstCall.returnValue);
|
||||
should.equal(options.transporter.sendMail.firstCall.args[0].html, options.getHTML.firstCall.returnValue);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue