mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
a565da06b2
refs https://github.com/TryGhost/Team/issues/1257 Offer Redemptions were being overcounted due to the way we were updating Stripe configuration for the Members service. We would create a new instance of the members-api, which would have event handlers for creating Offer Redemptions - by creating a new instance each time Stripe config changed, we would overcount them. Here we've pulled out Stripe related logic into the Stripe service, and updated it internally - rather than creating a new instance. This means that we've been able to remove all of the logic for re-instantiating the members-api. - Bumped members-api & stripe-service - Removed reinstantiation of members-api - Used stripe service to execute migrations - Updated Stripe Service to handle webhooks & migrations - Used webhook controller from stripe service - Used disconnect method from stripe service - Removed unused stripe dependency - Removed Stripe webhook config from members-api
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
const sinon = require('sinon');
|
|
const rewire = require('rewire');
|
|
|
|
const events = require('events');
|
|
|
|
const rewiredStripeService = rewire('../../../core/server/services/stripe');
|
|
|
|
describe('Stripe Service', function () {
|
|
beforeEach(function () {
|
|
this.clock = sinon.useFakeTimers();
|
|
});
|
|
|
|
afterEach(function () {
|
|
this.clock.restore();
|
|
});
|
|
|
|
it('Does not emit a "services.stripe.reconfigured" event when it is reconfigured', async function () {
|
|
const eventsStub = new events.EventEmitter();
|
|
const configureApiStub = sinon.spy();
|
|
|
|
const emitReconfiguredEventSpy = sinon.spy(eventsStub, 'emit').withArgs('services.stripe.reconfigured');
|
|
|
|
rewiredStripeService.__set__('events', eventsStub);
|
|
|
|
await rewiredStripeService.init();
|
|
|
|
// This is _after_ init, because init calls configureApi, and we DGAF about that call.
|
|
rewiredStripeService.__set__('configureApi', configureApiStub);
|
|
|
|
eventsStub.emit('settings.edited', {
|
|
get: sinon.stub().withArgs('key').returns('stripe_connect_secret_key')
|
|
});
|
|
|
|
this.clock.tick(600);
|
|
|
|
sinon.assert.notCalled(emitReconfiguredEventSpy);
|
|
});
|
|
});
|