Ghost/test/unit/server/services/members/config.test.js
Naz 7becf0a2b2 Aliased canary endpoints to point to non-versioned URLs
refs https://github.com/TryGhost/Toolbox/issues/169

- Before releasing Ghost v5 we would like to move all canary-related URLs to a non-versioned format, which will become a default in v5.
- 'canary' is by definition unstable, so breaking any unprepared client explicitly using the canary is expected
- Removed the aliased /content/ and /admin/ apps from app.js because with updated configuration they become duplicates of 'canary' endpoints
2022-03-14 21:22:54 +13:00

96 lines
3.1 KiB
JavaScript

const should = require('should');
const UrlUtils = require('@tryghost/url-utils');
const MembersConfigProvider = require('../../../../../core/server/services/members/config');
const configUtils = require('../../../../utils/configUtils');
const sinon = require('sinon');
/**
* @param {object} options
* @param {boolean} options.setDirect - Whether the "direct" keys should be set
* @param {boolean} options.setConnect - Whether the connect_integration keys should be set
*/
function createSettingsMock({setDirect, setConnect}) {
const getStub = sinon.stub();
getStub.withArgs('members_from_address').returns('noreply');
getStub.withArgs('members_signup_access').returns('all');
getStub.withArgs('stripe_secret_key').returns(setDirect ? 'direct_secret' : null);
getStub.withArgs('stripe_publishable_key').returns(setDirect ? 'direct_publishable' : null);
getStub.withArgs('stripe_product_name').returns('Test');
getStub.withArgs('stripe_plans').returns([{
name: 'Monthly',
currency: 'usd',
interval: 'month',
amount: 1000
}, {
name: 'Yearly',
currency: 'usd',
interval: 'year',
amount: 10000
}]);
getStub.withArgs('stripe_connect_secret_key').returns(setConnect ? 'connect_secret' : null);
getStub.withArgs('stripe_connect_publishable_key').returns(setConnect ? 'connect_publishable' : null);
getStub.withArgs('stripe_connect_livemode').returns(true);
getStub.withArgs('stripe_connect_display_name').returns('Test');
getStub.withArgs('stripe_connect_account_id').returns('ac_XXXXXXXXXXXXX');
return {
get: getStub
};
}
function createUrlUtilsMock() {
return new UrlUtils({
getSubdir: configUtils.config.getSubdir,
getSiteUrl: configUtils.config.getSiteUrl,
getAdminUrl: configUtils.config.getAdminUrl,
apiVersions: {
all: ['canary'],
canary: {
admin: 'admin',
content: 'content'
}
},
defaultApiVersion: 'canary',
slugs: ['ghost', 'rss', 'amp'],
redirectCacheMaxAge: 31536000,
baseApiPath: '/ghost/api'
});
}
describe('Members - config', function () {
beforeEach(function () {
configUtils.set({
url: 'http://domain.tld/subdir',
admin: {url: 'http://sub.domain.tld'}
});
});
afterEach(function () {
configUtils.restore();
});
it('Does not export webhookHandlerUrl', function () {
configUtils.set({
stripeDirect: false,
url: 'http://site.com/subdir'
});
const settingsCache = createSettingsMock({setDirect: true, setConnect: false});
const urlUtils = createUrlUtilsMock();
const membersConfig = new MembersConfigProvider({
config: configUtils.config,
settingsCache,
urlUtils,
ghostVersion: {original: 'v7357'},
logging: console
});
const paymentConfig = membersConfig.getStripePaymentConfig();
should.not.exist(paymentConfig.webhookHandlerUrl);
});
});