Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Stripe 3-D Secure intent handler specs #911

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading