0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/test/unit/server/services/members/config.test.js
Hannah Wolfe 499bb293c9
Fixed urlUtils usage in member config provider
- This is preparation work for getting rid of API versions
- The existing code used api versions for members, but the members API is not versioned
- This caused a bug as issuer was begin set to {{admin_url}}/ghost/api/undefined
- The updated code returns the correct value and is unit tested
- Whilst cleaning up I also swapped the usage of urlUtils to consistently use urlFor, as that is our main helper
2022-05-03 21:07:04 +01:00

88 lines
3.1 KiB
JavaScript

const assert = require('assert');
const sinon = require('sinon');
const MembersConfigProvider = require('../../../../../core/server/services/members/config');
const urlUtils = require('../../../../utils/urlUtils');
const configUtils = require('../../../../utils/configUtils');
/**
* @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');
getStub.withArgs('members_private_key').returns('PRIVATE');
getStub.withArgs('members_public_key').returns('PUBLIC');
return {
get: getStub
};
}
describe('Members - config', function () {
let membersConfig;
beforeEach(function () {
configUtils.set({
url: 'http://domain.tld/subdir',
admin: {url: 'http://sub.domain.tld'}
});
membersConfig = new MembersConfigProvider({
config: configUtils.config,
settingsCache: createSettingsMock({setDirect: true, setConnect: false}),
urlUtils: urlUtils.stubUrlUtilsFromConfig()
});
});
afterEach(function () {
configUtils.restore();
urlUtils.restore();
sinon.restore();
});
it('Does not export webhookHandlerUrl', function () {
const paymentConfig = membersConfig.getStripePaymentConfig();
assert.equal(paymentConfig.webhookHandlerUrl, undefined, 'webhookHandlerUrl should not exist');
});
it('can get correct tokenConfig', function () {
const {issuer, publicKey, privateKey} = membersConfig.getTokenConfig();
assert.equal(issuer, 'http://domain.tld/subdir/members/api');
assert.equal(publicKey, 'PUBLIC');
assert.equal(privateKey, 'PRIVATE');
});
it('can get correct signinUrl', function () {
const signinUrl = membersConfig.getSigninURL('a', 'b');
assert.equal(signinUrl, 'http://domain.tld/subdir/members/?token=a&action=b');
});
});