mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
6161f94910
refs: https://github.com/TryGhost/Toolbox/issues/595 We're rolling out new rules around the node assert library, the first of which is enforcing the use of assert/strict. This means we don't need to use the strict version of methods, as the standard version will work that way by default. This caught some gotchas in our existing usage of assert where the lack of strict mode had unexpected results: - Url matching needs to be done on `url.href` seeaa58b354a4
- Null and undefined are not the same thing, there were a few cases of this being confused - Particularly questionable changes in [PostExporter tests](c1a468744b
) tracked [here](https://github.com/TryGhost/Team/issues/3505). - A typo seeeaac9c293a
Moving forward, using assert strict should help us to catch unexpected behaviour, particularly around nulls and undefineds during implementation.
103 lines
4.9 KiB
JavaScript
103 lines
4.9 KiB
JavaScript
const assert = require('assert/strict');
|
|
const path = require('path');
|
|
|
|
const EmailContentGenerator = require('../index');
|
|
|
|
describe('Mail: EmailContentGenerator', function () {
|
|
it('generate welcome', async function () {
|
|
const emailContentGenerator = new EmailContentGenerator({
|
|
getSiteTitle: () => 'The Ghost Blog',
|
|
getSiteUrl: () => 'http://myblog.com',
|
|
templatesDir: path.resolve(__dirname, './fixtures/templates/')
|
|
});
|
|
|
|
const content = await emailContentGenerator.getContent({
|
|
template: 'welcome',
|
|
data: {
|
|
ownerEmail: 'test@example.com'
|
|
}
|
|
});
|
|
|
|
assert.match(content.html, /<title>Welcome to Ghost<\/title>/);
|
|
assert.match(content.html, /This email was sent from <a href="http:\/\/myblog.com" style="color: #738A94;">http:\/\/myblog.com<\/a> to <a href="mailto:test@example.com" style="color: #738A94;">test@example.com<\/a><\/p>/);
|
|
|
|
assert.match(content.text, /Email Address: test@example.com \[test@example.com\]/);
|
|
assert.match(content.text, /This email was sent from http:\/\/myblog.com/);
|
|
});
|
|
|
|
it('generates newsletter template', async function () {
|
|
const emailContentGenerator = new EmailContentGenerator({
|
|
getSiteTitle: () => 'The Ghost Blog',
|
|
getSiteUrl: () => 'http://myblog.com',
|
|
templatesDir: path.resolve(__dirname, './fixtures/templates/')
|
|
});
|
|
|
|
const content = await emailContentGenerator.getContent({
|
|
template: 'newsletter',
|
|
data: {
|
|
blog: {
|
|
logo: 'http://myblog.com/content/images/blog-logo.jpg',
|
|
title: 'The Ghost Blog',
|
|
url: 'http://myblog.com',
|
|
twitter: 'http://twitter.com/ghost',
|
|
facebook: 'https://www.facebook.com/ghost',
|
|
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'
|
|
}
|
|
}
|
|
});
|
|
|
|
assert.match(content.html, /<title>The Ghost Blog<\/title>/);
|
|
assert.match(content.html, /<span style="text-transform:capitalize">monthly<\/span> digest/);
|
|
assert.match(content.html, /<span style="text-transform:capitalize">june, 9th 2016<\/span><\/h3>/);
|
|
|
|
assert.match(content.text, /MONTHLY DIGEST — JUNE, 9TH 2016/);
|
|
assert.match(content.text, /SECOND BLOG POST \[HTTP:\/\/MYBLOG.COM\/SECOND-BLOG-POST\]/);
|
|
});
|
|
});
|