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

Fix bug when preflightDeviceData is set to false #903

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions lib/recurly/risk/three-d-secure/three-d-secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ export class ThreeDSecure extends RiskConcern {
const { gateway_code } = result.params;
const strategy = ThreeDSecure.getStrategyForGatewayType(gatewayType);
return strategy.preflight({ recurly, number, month, year, cvv, ...result.params })
.then(({ results, tokenType }) => {
// return finishedPreflights.concat([{ processor: type, gateway_code, results}]);
.then((preflightResponse) => {
if (!preflightResponse) return finishedPreflights;
const { results, tokenType } = preflightResponse;
return {
tokenType: finishedPreflights.tokenType || tokenType,
risk: finishedPreflights.risk.concat({
Expand Down
55 changes: 38 additions & 17 deletions test/unit/risk/three-d-secure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,57 @@ describe('ThreeDSecure', function () {

describe('ThreeDSecure.preflight', function () {
beforeEach(function () {
const { sandbox } = this;
this.bin = '411111';
this.preflights = [
{
gateway: { type: 'test-gateway-type' },
params: { arbitrary: 'test-params' }
}
];
sandbox.stub(ThreeDSecure, 'getStrategyForGatewayType').callsFake(() => ({
preflight: sandbox.stub().usingPromise(Promise).resolves({ results: { arbitrary: 'test-results' } })
}));
});

it('returns a promise', function (done) {
const { recurly, bin, preflights } = this;
const returnValue = ThreeDSecure.preflight({ recurly, bin, preflights }).then(() => done());
assert(returnValue instanceof Promise);
context('when a strategy returns valid results', function () {
beforeEach(function () {
this.sandbox.stub(ThreeDSecure, 'getStrategyForGatewayType').callsFake(() => ({
preflight: this.sandbox.stub().usingPromise(Promise).resolves({ results: { arbitrary: 'test-results' } })
}));
});

it('returns a promise', function (done) {
const { recurly, bin, preflights } = this;
const returnValue = ThreeDSecure.preflight({ recurly, bin, preflights }).then(() => done());
assert(returnValue instanceof Promise);
});

it('resolves with preflight results from strategies', function (done) {
const { recurly, bin, preflights } = this;
const returnValue = ThreeDSecure.preflight({ recurly, bin, preflights })
.done(({ risk }) => {
const [{ processor, results }] = risk;
assert.strictEqual(Array.isArray(risk), true);
assert.strictEqual(processor, 'test-gateway-type');
assert.deepStrictEqual(results, { arbitrary: 'test-results' });
done();
});
});
});

it('resolves with preflight results from strategies', function (done) {
const { recurly, bin, preflights } = this;
const returnValue = ThreeDSecure.preflight({ recurly, bin, preflights })
.done(({ risk }) => {
const [{ processor, results }] = risk;
assert.strictEqual(Array.isArray(risk), true);
assert.strictEqual(processor, 'test-gateway-type');
assert.deepStrictEqual(results, { arbitrary: 'test-results' });
context('when a strategy does not return results', function () {
beforeEach(function() {
this.sandbox.stub(ThreeDSecure, 'getStrategyForGatewayType').callsFake(() => ({
preflight: this.sandbox.stub().usingPromise(Promise).resolves(undefined)
}));
});

it('does not error out', function (done) {
const { recurly, bin, preflights } = this;
ThreeDSecure.preflight({ recurly, bin, preflights }).done(returnValue => {
assert(Array.isArray(returnValue.risk));
assert.strictEqual(returnValue.risk.length, 0);
done();
});
});
});
})
});

it('adds itself to the provided Risk instance', function () {
Expand Down
Loading