mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +03:00
f08a55c21f
refs: https://github.com/TryGhost/Team/issues/856 refs: https://github.com/TryGhost/Team/issues/756 - The .test.js extension is better than _spec.js as it's more obvious that it's an extension - It also meaans we can use the --extension parameter in mocha, which should result in a better default behaviour for `yarn test` - It also highlights that some of our tests were named incorrectly and were not (and still will not be) run (see https://github.com/TryGhost/Team/issues/856) - Note: even with this change, `yarn test` is throwing errors, I believe because of this issue https://github.com/TryGhost/Team/issues/756
85 lines
3.2 KiB
JavaScript
85 lines
3.2 KiB
JavaScript
const should = require('should');
|
|
|
|
const {parseReplacements, renderEmailForSegment} = require('../../../../core/server/services/mega/post-email-serializer');
|
|
|
|
describe('Post Email Serializer', function () {
|
|
it('creates replacement pattern for valid format and value', function () {
|
|
const html = '<html>Hey %%{first_name}%%, what is up?</html>';
|
|
const plaintext = 'Hey %%{first_name}%%, what is up?';
|
|
|
|
const replaced = parseReplacements({
|
|
html,
|
|
plaintext
|
|
});
|
|
|
|
replaced.length.should.equal(2);
|
|
replaced[0].format.should.equal('html');
|
|
replaced[0].recipientProperty.should.equal('member_first_name');
|
|
|
|
replaced[1].format.should.equal('plaintext');
|
|
replaced[1].recipientProperty.should.equal('member_first_name');
|
|
});
|
|
|
|
it('does not create replacements for unsupported variable names', function () {
|
|
const html = '<html>Hey %%{last_name}%%, what is up?</html>';
|
|
const plaintext = 'Hey %%{age}%%, what is up?';
|
|
|
|
const replaced = parseReplacements({
|
|
html,
|
|
plaintext
|
|
});
|
|
|
|
replaced.length.should.equal(0);
|
|
});
|
|
|
|
describe('renderEmailForSegment', function () {
|
|
it('shouldn\'t change an email that has no member segment', function () {
|
|
const email = {
|
|
otherProperty: true,
|
|
html: '<div>test</div>',
|
|
plaintext: 'test'
|
|
};
|
|
|
|
let output = renderEmailForSegment(email, 'status:free');
|
|
|
|
output.should.have.keys('html', 'plaintext', 'otherProperty');
|
|
output.html.should.eql('<div>test</div>');
|
|
output.plaintext.should.eql('test');
|
|
output.otherProperty.should.eql(true); // Make sure to keep other properties
|
|
});
|
|
|
|
it('should hide non matching member segments', function () {
|
|
const email = {
|
|
otherProperty: true,
|
|
html: 'hello<div data-gh-segment="status:free"> free users!</div><div data-gh-segment="status:-free"> paid users!</div>',
|
|
plaintext: 'test'
|
|
};
|
|
Object.freeze(email); // Make sure we don't modify `email`
|
|
|
|
let output = renderEmailForSegment(email, 'status:free');
|
|
|
|
output.should.have.keys('html', 'plaintext', 'otherProperty');
|
|
output.html.should.eql('hello<div> free users!</div>');
|
|
output.plaintext.should.eql('hello free users!');
|
|
|
|
output = renderEmailForSegment(email, 'status:-free');
|
|
|
|
output.should.have.keys('html', 'plaintext', 'otherProperty');
|
|
output.html.should.eql('hello<div> paid users!</div>');
|
|
output.plaintext.should.eql('hello paid users!');
|
|
});
|
|
|
|
it('should hide all segments when the segment filter is empty', function () {
|
|
const email = {
|
|
otherProperty: true,
|
|
html: 'hello<div data-gh-segment="status:free"> free users!</div><div data-gh-segment="status:-free"> paid users!</div>',
|
|
plaintext: 'test'
|
|
};
|
|
|
|
let output = renderEmailForSegment(email, null);
|
|
output.html.should.equal('hello');
|
|
output.plaintext.should.equal('hello');
|
|
});
|
|
});
|
|
});
|