From ee97017679a6d9c579aa93a6971046bb76aba9c6 Mon Sep 17 00:00:00 2001 From: Samuel Judson Date: Wed, 25 Oct 2017 13:15:09 -0500 Subject: [PATCH] Add support for custom transaction loaders. --- lib/server.js | 9 ++++++++- test/server.test.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index ad9df9d6..631a5d37 100644 --- a/lib/server.js +++ b/lib/server.js @@ -138,10 +138,17 @@ Server.prototype.authorization = function(options, validate, immediate, complete }; Server.prototype.resume = function(options, immediate, complete) { + var ld = transactionLoader; + if (options && options.loadTransaction === false) { return resume(this, options, immediate, complete); } - return [transactionLoader(this, options), resume(this, options, immediate, complete)]; + + if (options && typeof options.loadTransaction === 'function') { + ld = options.loadTransaction; + } + + return [ld(this, options), resume(this, options, immediate, complete)]; }; /** diff --git a/test/server.test.js b/test/server.test.js index 666b7252..dce17bd4 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -89,6 +89,18 @@ describe('Server', function() { expect(handler).to.be.an('function'); expect(handler).to.have.length(3); }); + + it('should employ custom transaction loader', function() { + function customLoader(server, options) { return function customTransaction(req, res, next) {}; }; + var handler = server.resume({ loadTransaction: customLoader }, function(){}); + expect(handler).to.be.an('array'); + expect(handler).to.have.length(2); + expect(handler[0]).to.be.a('function'); + expect(handler[0].name).to.equal('customTransaction'); + expect(handler[0]).to.have.length(3); + expect(handler[1]).to.be.a('function'); + expect(handler[1]).to.have.length(3); + }); }); describe('#decision', function() {