Skip to content

Commit

Permalink
Merge pull request #217 from sjudson/set-txn-loader
Browse files Browse the repository at this point in the history
Add support for custom transaction loaders.
  • Loading branch information
jaredhanson committed Oct 26, 2017
2 parents b707600 + ee97017 commit f19e1c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/server.js
Expand Up @@ -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)];
};

/**
Expand Down
12 changes: 12 additions & 0 deletions test/server.test.js
Expand Up @@ -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() {
Expand Down

0 comments on commit f19e1c5

Please sign in to comment.