Skip to content

Commit

Permalink
test wrangling
Browse files Browse the repository at this point in the history
  • Loading branch information
cathysarisky committed Oct 29, 2024
1 parent 6240f25 commit 6c0adf3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
44 changes: 30 additions & 14 deletions ghost/email-service/test/email-helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
const assert = require('assert/strict');
const {registerHelpers} = require('../lib/helpers/register-helpers');

// load the i18n module
const i18nLib = require('@tryghost/i18n');
const i18n = i18nLib('fr', 'newsletter');

const t = (key, options) => {
return i18n.t(key, options);
};

describe('registerHelpers', function () {
it('registers helpers', function () {
const handlebars = {
Expand All @@ -20,6 +28,7 @@ describe('registerHelpers', function () {
assert.ok(handlebars.not);
assert.ok(handlebars.or);
assert.ok(handlebars.hasFeature);
assert.ok(handlebars.t);
});

it('if helper returns true', function () {
Expand Down Expand Up @@ -139,31 +148,38 @@ describe('registerHelpers', function () {

assert.equal(result, false);
});
it('can translate', function () {
it('t helper returns key', function () {
const labs = {
isSet: function () {
return false;
}
};
const handlebars = {
registerHelper: function (name, fn) {
this[name] = fn;
}
};

registerHelpers(handlebars, labs, t);

const result = handlebars.t('test');
assert.equal(result, 'test');
});
it('t helper returns translation', function () {
const labs = {
isSet: function () {
return true;
return false;
}
};
const thist = function (key, options) {
return key;
const handlebars = {
registerHelper: function (name, fn) {
this[name] = fn;
}
};
registerHelpers(handlebars, labs, thist);

const result = handlebars.t('test', {
fn: function () {
return true;
},
inverse: function () {
return false;
}
});
registerHelpers(handlebars, labs, t);

assert.equal(result, 'test');
const result = handlebars.t('Name');
assert.equal(result, 'Nom');
});
});
23 changes: 11 additions & 12 deletions ghost/email-service/test/email-renderer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ const createUnsubscribeUrl = (uuid) => {
const getMembersValidationKey = () => {
return 'members-key';
};
// stub the t function so that we don't need to load the i18n module
// actually, no, this is a terrible option, because then we don't actually get interpolation.
// we should probably just load the i18n module

describe('Email renderer', function () {
let logStub;
// stub the t function so that we don't need to load the i18n module
// actually, no, this is a terrible option, because then we don't actually get interpolation.
// we should probably just load the i18n module
// load the i18n module
const i18nLib = require('@tryghost/i18n');
const i18n = i18nLib('en', 'newsletter');

// load the i18n module
const i18nLib = require('@tryghost/i18n');
const i18n = i18nLib('en', 'newsletter');
const t = (key, options) => {
return i18n.t(key, options);
};

const t = (key, options) => {
return i18n.t(key, options);
};
describe('Email renderer', function () {
let logStub;

beforeEach(function () {
logStub = sinon.stub(logging, 'error');
Expand Down Expand Up @@ -225,7 +225,6 @@ describe('Email renderer', function () {
it('returns mapped complimentary status', function () {
member.status = 'comped';
const html = 'Hello %%{status}%%,';
console.log('start emailRenderer');
const replacements = emailRenderer.buildReplacementDefinitions({html, newsletterUuid: newsletter.get('uuid')});
assert.equal(replacements.length, 2);
assert.equal(replacements[0].token.toString(), '/%%\\{status\\}%%/g');
Expand Down

0 comments on commit 6c0adf3

Please sign in to comment.