Skip to content

Commit

Permalink
Make function signature of resume prettier for loadTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Oct 26, 2017
1 parent 046306a commit 8b7b430
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
13 changes: 7 additions & 6 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,20 @@ Server.prototype.authorization = function(options, validate, immediate, complete
};

Server.prototype.resume = function(options, immediate, complete) {
var ld;
var loader;
if (typeof options == 'function' && typeof immediate == 'function' && typeof complete == 'function') {
options = { loadTransaction: options };
}

if (options && options.loadTransaction === false) {
return resume(this, options, immediate, complete);
}

if (options && typeof options.loadTransaction === 'function') {
ld = options.loadTransaction;
loader = options.loadTransaction;
} else {
ld = transactionLoader(this, options);
loader = transactionLoader(this, options);
}

return [ld, resume(this, options, immediate, complete)];
return [loader, resume(this, options, immediate, complete)];
};

/**
Expand Down
20 changes: 16 additions & 4 deletions test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,25 @@ describe('Server', function() {
expect(handler).to.have.length(3);
});

it('should employ custom transaction loader', function() {
function customTransaction(req, res, next) {};
var handler = server.resume({ loadTransaction: customTransaction }, function(){});
it('should create handler stack with custom transaction loader', function() {
function loadTransaction(req, res, next) {};
var handler = server.resume({ loadTransaction: loadTransaction }, 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].name).to.equal('loadTransaction');
expect(handler[0]).to.have.length(3);
expect(handler[1]).to.be.a('function');
expect(handler[1]).to.have.length(3);
});

it('should create handler stack with custom transaction loader using non-object signature', function() {
function loadTransaction(req, res, next) {};
var handler = server.resume(loadTransaction, function(){}, 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('loadTransaction');
expect(handler[0]).to.have.length(3);
expect(handler[1]).to.be.a('function');
expect(handler[1]).to.have.length(3);
Expand Down

0 comments on commit 8b7b430

Please sign in to comment.