mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs https://github.com/TryGhost/Team/issues/1083 The Offers service is going to need access to the StripeAPIService too, so we need to move it out of the @tryghost/members-api module and make it accessible to both.
85 lines
3.4 KiB
JavaScript
85 lines
3.4 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
|
|
const {getConfig} = require('../../../../core/server/services/stripe/config');
|
|
|
|
describe('Stripe - config', function () {
|
|
it('Uses direct keys when stripeDirect is true, regardles of which keys exist', function () {
|
|
const fakeSettings = {
|
|
get: sinon.stub()
|
|
};
|
|
const fakeConfig = {
|
|
get: sinon.stub()
|
|
};
|
|
|
|
fakeSettings.get.withArgs('stripe_connect_secret_key').returns('connect_secret');
|
|
fakeSettings.get.withArgs('stripe_connect_publishable_key').returns('connect_publishable');
|
|
fakeSettings.get.withArgs('stripe_secret_key').returns('direct_secret');
|
|
fakeSettings.get.withArgs('stripe_publishable_key').returns('direct_publishable');
|
|
fakeConfig.get.withArgs('stripeDirect').returns(true);
|
|
|
|
const config = getConfig(fakeSettings, fakeConfig);
|
|
|
|
should.equal(config.publicKey, 'direct_publishable');
|
|
should.equal(config.secretKey, 'direct_secret');
|
|
});
|
|
|
|
it('Does not use connect keys if stripeDirect is true, and the direct keys do not exist', function () {
|
|
const fakeSettings = {
|
|
get: sinon.stub()
|
|
};
|
|
const fakeConfig = {
|
|
get: sinon.stub()
|
|
};
|
|
|
|
fakeSettings.get.withArgs('stripe_connect_secret_key').returns('connect_secret');
|
|
fakeSettings.get.withArgs('stripe_connect_publishable_key').returns('connect_publishable');
|
|
fakeSettings.get.withArgs('stripe_secret_key').returns(null);
|
|
fakeSettings.get.withArgs('stripe_publishable_key').returns(null);
|
|
fakeConfig.get.withArgs('stripeDirect').returns(true);
|
|
|
|
const config = getConfig(fakeSettings, fakeConfig);
|
|
|
|
should.equal(config, null);
|
|
});
|
|
|
|
it('Uses connect keys when stripeDirect is false, and the connect keys exist', function () {
|
|
const fakeSettings = {
|
|
get: sinon.stub()
|
|
};
|
|
const fakeConfig = {
|
|
get: sinon.stub()
|
|
};
|
|
|
|
fakeSettings.get.withArgs('stripe_connect_secret_key').returns('connect_secret');
|
|
fakeSettings.get.withArgs('stripe_connect_publishable_key').returns('connect_publishable');
|
|
fakeSettings.get.withArgs('stripe_secret_key').returns('direct_secret');
|
|
fakeSettings.get.withArgs('stripe_publishable_key').returns('direct_publishable');
|
|
fakeConfig.get.withArgs('stripeDirect').returns(false);
|
|
|
|
const config = getConfig(fakeSettings, fakeConfig);
|
|
|
|
should.equal(config.publicKey, 'connect_publishable');
|
|
should.equal(config.secretKey, 'connect_secret');
|
|
});
|
|
|
|
it('Uses direct keys when stripeDirect is false, but the connect keys do not exist', function () {
|
|
const fakeSettings = {
|
|
get: sinon.stub()
|
|
};
|
|
const fakeConfig = {
|
|
get: sinon.stub()
|
|
};
|
|
|
|
fakeSettings.get.withArgs('stripe_connect_secret_key').returns(null);
|
|
fakeSettings.get.withArgs('stripe_connect_publishable_key').returns(null);
|
|
fakeSettings.get.withArgs('stripe_secret_key').returns('direct_secret');
|
|
fakeSettings.get.withArgs('stripe_publishable_key').returns('direct_publishable');
|
|
fakeConfig.get.withArgs('stripeDirect').returns(false);
|
|
|
|
const config = getConfig(fakeSettings, fakeConfig);
|
|
|
|
should.equal(config.publicKey, 'direct_publishable');
|
|
should.equal(config.secretKey, 'direct_secret');
|
|
});
|
|
});
|