Skip to content

Commit

Permalink
test: address trim transform options
Browse files Browse the repository at this point in the history
  • Loading branch information
Braydon Fuller committed Jul 20, 2016
1 parent 5e72240 commit 5eb32cf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ AddressController.prototype.transformUtxo = function(utxoArg) {
return utxo;
};

AddressController.prototype._getTransformOptions = function(req) {
return {
noAsm: parseInt(req.query.noAsm) ? true : false,
noScriptSig: parseInt(req.query.noScriptSig) ? true : false,
noSpent: parseInt(req.query.noSpent) ? true : false
};
};

AddressController.prototype.multitxs = function(req, res, next) {
var self = this;

Expand All @@ -183,11 +191,7 @@ AddressController.prototype.multitxs = function(req, res, next) {
return self.common.handleErrors(err, res);
}

var transformOptions = {
noAsm: req.query.noAsm ? true : false,
noScriptSig: req.query.noScriptSig ? true : false,
noSpent: req.query.noSpent ? true : false
};
var transformOptions = self._getTransformOptions(req);

self.transformAddressHistoryForMultiTxs(result.items, transformOptions, function(err, items) {
if (err) {
Expand Down
53 changes: 53 additions & 0 deletions test/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,4 +714,57 @@ describe('Addresses', function() {
addresses.multitxs(req, res);
});
});
describe('#_getTransformOptions', function() {
it('will return false with value of string "0"', function() {
var node = {};
var addresses = new AddressController(node);
var req = {
query: {
noAsm: '0',
noScriptSig: '0',
noSpent: '0'
}
};
var options = addresses._getTransformOptions(req);
options.should.eql({
noAsm: false,
noScriptSig: false,
noSpent: false
});
});
it('will return true with value of string "1"', function() {
var node = {};
var addresses = new AddressController(node);
var req = {
query: {
noAsm: '1',
noScriptSig: '1',
noSpent: '1'
}
};
var options = addresses._getTransformOptions(req);
options.should.eql({
noAsm: true,
noScriptSig: true,
noSpent: true
});
});
it('will return true with value of number "1"', function() {
var node = {};
var addresses = new AddressController(node);
var req = {
query: {
noAsm: 1,
noScriptSig: 1,
noSpent: 1
}
};
var options = addresses._getTransformOptions(req);
options.should.eql({
noAsm: true,
noScriptSig: true,
noSpent: true
});
});
});
});

0 comments on commit 5eb32cf

Please sign in to comment.