Skip to content

Commit

Permalink
Merge pull request #911 from recurly/stripe-use-handleNextAction
Browse files Browse the repository at this point in the history
Fixes Stripe 3-D Secure intent handler specs
  • Loading branch information
btruncali1 authored Dec 12, 2024
2 parents cb7fe80 + 9fb76d3 commit 8498a35
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions test/unit/risk/three-d-secure/strategy/stripe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ describe('StripeStrategy', function () {
this.target = testBed().querySelector('#three-d-secure-container');
this.sandbox = sinon.createSandbox();

this.paymentIntentResult = {
this.intentResult = {
paymentIntent: { id: 'pi-test-id', test: 'result', consistingOf: 'arbitrary-values' }
};
this.setupIntentResult = {
setupIntent: { id: 'seti-test-id', test: 'result', consistingOf: 'arbitrary-values' }
};
this.stripe = {
handleNextAction: sinon.stub().resolves(this.paymentIntentResult),
confirmCardSetup: sinon.stub().resolves(this.setupIntentResult)
handleNextAction: sinon.stub().resolves(this.intentResult),
};
window.Stripe = sinon.spy(publishableKey => this.stripe);
});
Expand Down Expand Up @@ -83,7 +79,7 @@ describe('StripeStrategy', function () {
});

it('emits done with the paymentIntent result', function (done) {
const { strategy, target, paymentIntentResult: { paymentIntent: { id } } } = this;
const { strategy, target, intentResult: { paymentIntent: { id } } } = this;
strategy.on('done', result => {
assert.deepEqual(result, { id });
done();
Expand Down Expand Up @@ -115,17 +111,20 @@ describe('StripeStrategy', function () {
const { threeDSecure } = this;
this.strategy = new StripeStrategy({ threeDSecure, actionToken: actionTokenSetupIntent });
this.strategy.whenReady(() => done());
this.intentResult = {
setupIntent: { id: 'pi-test-id', test: 'result', consistingOf: 'arbitrary-values' }
};
});

it('instructs Stripe.js to handle the card action using the client secret', function () {
const { strategy, target, stripe } = this;
strategy.attach(target);
assert(stripe.confirmCardSetup.calledOnce);
assert(stripe.confirmCardSetup.calledWithExactly('seti-test-stripe-client-secret'));
assert(stripe.handleNextAction.calledOnce);
assert(stripe.handleNextAction.calledWithExactly({ clientSecret: 'seti-test-stripe-client-secret' }));
});

it('emits done with the setupIntent result', function (done) {
const { strategy, target, setupIntentResult: { setupIntent: { id } } } = this;
const { strategy, target, intentResult: { setupIntent: { id } } } = this;
strategy.on('done', result => {
assert.deepEqual(result, { id });
done();
Expand All @@ -137,7 +136,7 @@ describe('StripeStrategy', function () {
beforeEach(function () {
const { strategy } = this;
this.exampleResult = { error: { example: 'error', for: 'testing' } };
strategy.stripe.confirmCardSetup = sinon.stub().resolves(this.exampleResult);
strategy.stripe.handleNextAction = sinon.stub().resolves(this.exampleResult);
});

it('emits an error on threeDSecure', function (done) {
Expand Down

0 comments on commit 8498a35

Please sign in to comment.