Ghost/test/unit/server/services/mail/utils.test.js

108 lines
4.3 KiB
JavaScript
Raw Normal View History

const should = require('should');
const sinon = require('sinon');
const mail = require('../../../../../core/server/services/mail');
const configUtils = require('../../../../utils/configUtils');
describe('Mail: Utils', function () {
const scope = {ghostMailer: null};
HTML newsletter template for subscribers (#7045) refs #7023 The template can be used for all cases (different newsletter interval, different amount of blog posts, with or without blog picture). The template can be filled with the following data structure: - `blog.logo` is the blog logo from settings - `blog.title` is the title of the current blog - `blog.url` is the URL of the blog - `blog.twitterURL` is the twitter profile URL of the blog from settings - `blog.facebookURL` is the facebook page URL of the blog from settings - `blog.unsubscribe` is the link for the reader to unsubscribe from the blog - `newsletter.interval` is the interval in words like 'weekly', 'daily', 'monthly' - `newsletter.date` is the date of the newsletter issue in a format like 'June 9th, 2016' - `blog.post` is expected to be an array: - `blog.post[i].picture` is the picture of the blog post. There are also conditionals, which change the inline CSS to either show a border-top if there's no picture (in that case the HTML code, that shows the picture is not active) - `blog.post[i].title` is the title of the current blog post - `blog.post[i].text` is the text of the current blog post, which needs to be cut down to 278 letters, plus ending with `…` - `blog.post[i].url` is the URL of the current blog post - `blog.post[i].tag` is the tag of the current blog post - `blog.post[i].author` is the author of the current blog post Important is, that only HEX HTML entities will work, especially in Outlook. So instead of `—` we need to use `—` and `’` instead of `'` or `'` and so on. Added unit test for newsletter template in `test/unit/mail/utils_spec.js`.
2016-07-09 06:40:32 +03:00
beforeEach(function () {
configUtils.set({mail: {transport: 'stub'}});
scope.ghostMailer = new mail.GhostMailer();
});
HTML newsletter template for subscribers (#7045) refs #7023 The template can be used for all cases (different newsletter interval, different amount of blog posts, with or without blog picture). The template can be filled with the following data structure: - `blog.logo` is the blog logo from settings - `blog.title` is the title of the current blog - `blog.url` is the URL of the blog - `blog.twitterURL` is the twitter profile URL of the blog from settings - `blog.facebookURL` is the facebook page URL of the blog from settings - `blog.unsubscribe` is the link for the reader to unsubscribe from the blog - `newsletter.interval` is the interval in words like 'weekly', 'daily', 'monthly' - `newsletter.date` is the date of the newsletter issue in a format like 'June 9th, 2016' - `blog.post` is expected to be an array: - `blog.post[i].picture` is the picture of the blog post. There are also conditionals, which change the inline CSS to either show a border-top if there's no picture (in that case the HTML code, that shows the picture is not active) - `blog.post[i].title` is the title of the current blog post - `blog.post[i].text` is the text of the current blog post, which needs to be cut down to 278 letters, plus ending with `…` - `blog.post[i].url` is the URL of the current blog post - `blog.post[i].tag` is the tag of the current blog post - `blog.post[i].author` is the author of the current blog post Important is, that only HEX HTML entities will work, especially in Outlook. So instead of `—` we need to use `—` and `’` instead of `'` or `'` and so on. Added unit test for newsletter template in `test/unit/mail/utils_spec.js`.
2016-07-09 06:40:32 +03:00
afterEach(function () {
sinon.restore();
configUtils.restore();
});
it('generate welcome', function (done) {
mail.utils.generateContent({
template: 'welcome',
data: {
ownerEmail: 'test@example.com'
}
}).then(function (result) {
return scope.ghostMailer.send({
to: 'test@example.com',
subject: 'lol',
html: result.html,
text: result.text
});
}).then(function () {
done();
}).catch(done);
});
HTML newsletter template for subscribers (#7045) refs #7023 The template can be used for all cases (different newsletter interval, different amount of blog posts, with or without blog picture). The template can be filled with the following data structure: - `blog.logo` is the blog logo from settings - `blog.title` is the title of the current blog - `blog.url` is the URL of the blog - `blog.twitterURL` is the twitter profile URL of the blog from settings - `blog.facebookURL` is the facebook page URL of the blog from settings - `blog.unsubscribe` is the link for the reader to unsubscribe from the blog - `newsletter.interval` is the interval in words like 'weekly', 'daily', 'monthly' - `newsletter.date` is the date of the newsletter issue in a format like 'June 9th, 2016' - `blog.post` is expected to be an array: - `blog.post[i].picture` is the picture of the blog post. There are also conditionals, which change the inline CSS to either show a border-top if there's no picture (in that case the HTML code, that shows the picture is not active) - `blog.post[i].title` is the title of the current blog post - `blog.post[i].text` is the text of the current blog post, which needs to be cut down to 278 letters, plus ending with `…` - `blog.post[i].url` is the URL of the current blog post - `blog.post[i].tag` is the tag of the current blog post - `blog.post[i].author` is the author of the current blog post Important is, that only HEX HTML entities will work, especially in Outlook. So instead of `—` we need to use `—` and `’` instead of `'` or `'` and so on. Added unit test for newsletter template in `test/unit/mail/utils_spec.js`.
2016-07-09 06:40:32 +03:00
it('generates newsletter template', function (done) {
mail.utils.generateContent({
template: 'newsletter',
data: {
blog: {
logo: 'http://myblog.com/content/images/blog-logo.jpg',
title: 'The Ghost Blog',
url: 'http://myblog.com',
2019-10-16 04:27:30 +03:00
twitter: 'http://twitter.com/ghost',
facebook: 'https://www.facebook.com/ghost',
HTML newsletter template for subscribers (#7045) refs #7023 The template can be used for all cases (different newsletter interval, different amount of blog posts, with or without blog picture). The template can be filled with the following data structure: - `blog.logo` is the blog logo from settings - `blog.title` is the title of the current blog - `blog.url` is the URL of the blog - `blog.twitterURL` is the twitter profile URL of the blog from settings - `blog.facebookURL` is the facebook page URL of the blog from settings - `blog.unsubscribe` is the link for the reader to unsubscribe from the blog - `newsletter.interval` is the interval in words like 'weekly', 'daily', 'monthly' - `newsletter.date` is the date of the newsletter issue in a format like 'June 9th, 2016' - `blog.post` is expected to be an array: - `blog.post[i].picture` is the picture of the blog post. There are also conditionals, which change the inline CSS to either show a border-top if there's no picture (in that case the HTML code, that shows the picture is not active) - `blog.post[i].title` is the title of the current blog post - `blog.post[i].text` is the text of the current blog post, which needs to be cut down to 278 letters, plus ending with `…` - `blog.post[i].url` is the URL of the current blog post - `blog.post[i].tag` is the tag of the current blog post - `blog.post[i].author` is the author of the current blog post Important is, that only HEX HTML entities will work, especially in Outlook. So instead of `—` we need to use `—` and `’` instead of `'` or `'` and so on. Added unit test for newsletter template in `test/unit/mail/utils_spec.js`.
2016-07-09 06:40:32 +03:00
unsubscribe: 'http://myblog.com/unsubscribe',
post: [
{
picture: 'http://myblog.com/content/images/post-1-image.jpg',
title: 'Featured blog post',
text: 'This is a featured blog post. It’s awesome…',
url: 'http://myblog.com/featured-blog-post',
tag: 'featured',
author: 'harry potter'
},
{
picture: 'http://myblog.com/content/images/post-2-image.jpg',
title: 'Second blog post',
text: 'This is the second blog post. It’s also awesome…',
url: 'http://myblog.com/second-blog-post',
tag: 'second',
author: 'lord voldemord'
},
{
picture: 'http://myblog.com/content/images/post-3-image.jpg',
title: 'Third blog post',
text: 'This is the third blog post. It’s also awesome…',
url: 'http://myblog.com/third-blog-post',
tag: 'third',
author: 'marry poppins'
},
{
picture: 'http://myblog.com/content/images/post-4-image.jpg',
title: 'Fourth blog post',
text: 'This is the fourth blog post. It’s also awesome…',
url: 'http://myblog.com/fourth-blog-post',
tag: 'fourth',
author: 'donald duck'
},
{
picture: 'http://myblog.com/content/images/post-5-image.jpg',
title: 'Fifth blog post',
text: 'This is the fifth blog post. It’s also awesome…',
url: 'http://myblog.com/fifth-blog-post',
tag: 'fifth',
author: 'casper the ghost'
}
]
},
newsletter: {
interval: 'monthly',
date: 'june, 9th 2016'
}
}
}).then(function (result) {
return scope.ghostMailer.send({
to: 'jbloggs@example.com',
HTML newsletter template for subscribers (#7045) refs #7023 The template can be used for all cases (different newsletter interval, different amount of blog posts, with or without blog picture). The template can be filled with the following data structure: - `blog.logo` is the blog logo from settings - `blog.title` is the title of the current blog - `blog.url` is the URL of the blog - `blog.twitterURL` is the twitter profile URL of the blog from settings - `blog.facebookURL` is the facebook page URL of the blog from settings - `blog.unsubscribe` is the link for the reader to unsubscribe from the blog - `newsletter.interval` is the interval in words like 'weekly', 'daily', 'monthly' - `newsletter.date` is the date of the newsletter issue in a format like 'June 9th, 2016' - `blog.post` is expected to be an array: - `blog.post[i].picture` is the picture of the blog post. There are also conditionals, which change the inline CSS to either show a border-top if there's no picture (in that case the HTML code, that shows the picture is not active) - `blog.post[i].title` is the title of the current blog post - `blog.post[i].text` is the text of the current blog post, which needs to be cut down to 278 letters, plus ending with `…` - `blog.post[i].url` is the URL of the current blog post - `blog.post[i].tag` is the tag of the current blog post - `blog.post[i].author` is the author of the current blog post Important is, that only HEX HTML entities will work, especially in Outlook. So instead of `—` we need to use `—` and `’` instead of `'` or `'` and so on. Added unit test for newsletter template in `test/unit/mail/utils_spec.js`.
2016-07-09 06:40:32 +03:00
subject: 'The Newsletter Blog',
html: result.html,
text: result.text
});
}).then(function () {
done();
}).catch(done);
});
});