mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
9e96b04542
- this is a small part of a bit of cleanup of our test files - the goal is to make the existing tests clearer with a view to making it easier to write more tests - this makes the test structure follow the codebase structure more closely - eventually we will colocate the tests as we break the codebase down further
86 lines
3.4 KiB
JavaScript
86 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');
|
|
});
|
|
});
|