Skip to content

Commit

Permalink
write test for bug scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
gilv93 committed Oct 1, 2024
1 parent f216139 commit f4b578c
Showing 1 changed file with 38 additions and 17 deletions.
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

0 comments on commit f4b578c

Please sign in to comment.