mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Moved labs usage into cancel_link helper file
- this removes the need to require the proxy inside the helpers/index.js file - have the helper file define and return it's own labs-enabled-ness - update the tests to test for the labs flag being unset
This commit is contained in:
parent
b37ac8ef1f
commit
e639a25171
3 changed files with 46 additions and 18 deletions
|
@ -6,9 +6,9 @@
|
|||
//
|
||||
// Defaults to class="cancel-subscription-link" errorClass="cancel-subscription-error" cancelLabel="Cancel subscription" continueLabel="Continue subscription"
|
||||
|
||||
const {templates, errors, i18n} = require('../services/proxy');
|
||||
const {templates, errors, i18n, labs} = require('../services/proxy');
|
||||
|
||||
module.exports = function excerpt(options) {
|
||||
function cancel_link(options) { // eslint-disable-line camelcase
|
||||
let truncateOptions = (options || {}).hash || {};
|
||||
|
||||
if (this.id === undefined || this.cancel_at_period_end === undefined) {
|
||||
|
@ -25,4 +25,18 @@ module.exports = function excerpt(options) {
|
|||
};
|
||||
|
||||
return templates.execute('cancel_link', data);
|
||||
}
|
||||
|
||||
module.exports = function cancelLabsWrapper() {
|
||||
let self = this;
|
||||
let args = arguments;
|
||||
|
||||
return labs.enabledHelper({
|
||||
flagKey: 'members',
|
||||
flagName: 'Members',
|
||||
helperName: 'cancel_link',
|
||||
helpUrl: 'https://ghost.org/faq/members/'
|
||||
}, () => {
|
||||
return cancel_link.apply(self, args);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
const proxy = require('../services/proxy');
|
||||
const register = require('./register');
|
||||
|
||||
const coreHelpers = {};
|
||||
|
@ -46,26 +45,13 @@ coreHelpers.title = require('./title');
|
|||
coreHelpers.twitter_url = require('./twitter_url');
|
||||
coreHelpers.url = require('./url');
|
||||
|
||||
function labsEnabledMembers() {
|
||||
let self = this, args = arguments;
|
||||
|
||||
return proxy.labs.enabledHelper({
|
||||
flagKey: 'members',
|
||||
flagName: 'Members',
|
||||
helperName: 'cancel_link',
|
||||
helpUrl: 'https://ghost.org/faq/members/'
|
||||
}, () => {
|
||||
return coreHelpers.cancel_link.apply(self, args);
|
||||
});
|
||||
}
|
||||
|
||||
registerAllCoreHelpers = function registerAllCoreHelpers() {
|
||||
// Register theme helpers
|
||||
registerThemeHelper('asset', coreHelpers.asset);
|
||||
registerThemeHelper('author', coreHelpers.author);
|
||||
registerThemeHelper('authors', coreHelpers.authors);
|
||||
registerThemeHelper('body_class', coreHelpers.body_class);
|
||||
registerThemeHelper('cancel_link', labsEnabledMembers);
|
||||
registerThemeHelper('cancel_link', coreHelpers.cancel_link);
|
||||
registerThemeHelper('concat', coreHelpers.concat);
|
||||
registerThemeHelper('content', coreHelpers.content);
|
||||
registerThemeHelper('date', coreHelpers.date);
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const hbs = require('../../../core/frontend/services/themes/engine');
|
||||
const helpers = require('../../../core/frontend/helpers');
|
||||
const labs = require('../../../core/server/services/labs');
|
||||
const configUtils = require('../../utils/configUtils');
|
||||
|
||||
describe('{{cancel_link}} helper', function () {
|
||||
let labsStub;
|
||||
before(function (done) {
|
||||
hbs.express4({partialsDir: [configUtils.config.get('paths').helperTemplates]});
|
||||
|
||||
|
@ -12,6 +15,14 @@ describe('{{cancel_link}} helper', function () {
|
|||
});
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
labsStub = sinon.stub(labs, 'isSet').returns(true);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
const defaultLinkClass = /class="gh-subscription-cancel"/;
|
||||
const defaultErrorElementClass = /class="gh-error gh-error-subscription-cancel"/;
|
||||
const defaultCancelLinkText = /Cancel subscription/;
|
||||
|
@ -25,7 +36,10 @@ describe('{{cancel_link}} helper', function () {
|
|||
};
|
||||
|
||||
runHelper('not an object').should.throw();
|
||||
runHelper(function () {}).should.throw();
|
||||
runHelper(function () { }).should.throw();
|
||||
runHelper({}).should.throw();
|
||||
runHelper({id: ''}).should.throw();
|
||||
runHelper({cancel_at_period_end: ''}).should.throw();
|
||||
});
|
||||
|
||||
it('can render cancel subscription link', function () {
|
||||
|
@ -109,4 +123,18 @@ describe('{{cancel_link}} helper', function () {
|
|||
|
||||
rendered.string.should.match(/custom continue link text/);
|
||||
});
|
||||
|
||||
it('is disabled if labs flag is not set', function () {
|
||||
labsStub.returns(false);
|
||||
|
||||
const rendered = helpers.cancel_link.call({
|
||||
id: 'sub_continue',
|
||||
cancel_at_period_end: true
|
||||
});
|
||||
|
||||
should.exist(rendered);
|
||||
|
||||
rendered.string.should.match(/^<script/);
|
||||
rendered.string.should.match(/helper is not available/);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue