Skip to content

Commit

Permalink
check if result is simply null
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Sep 22, 2023
1 parent 974e266 commit e52ff91
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/myutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ function expandVar(val, mapping, trycast) {
}
if (!expanded) {
val = val.replace(/\$\{\w*\}/g, 'null');
if (val === 'null') {
val = null;
}
}
}
return val;
Expand Down Expand Up @@ -123,7 +126,7 @@ function requestHelperAux(method, options, withMetrics, callback) {
headers,
domain = process.domain;
logger.info('making %s to %s', method, options.url);
if (withMetrics && domain.context) {
if (withMetrics && domain && domain.context) {
metrics.IncMetrics(domain.context.srv, domain.context.subsrv, metrics.outgoingTransactions);
}
headers = options.headers || {};
Expand Down
67 changes: 67 additions & 0 deletions test/component/myutils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,73 @@ describe('Myutils', function() {
newStr.should.be.equal(str);
});
});
describe('When there is a variable which is a number', function() {
it('should return the number', function() {
var str = '${a}',
map = { a: 23 },
newStr;
newStr = myutils.expandVar(str, map, true);
should.exist(newStr);
newStr.should.be.equal(23);
});
});
describe('When there is a variable which is a string number', function() {
it('should return the number', function() {
var str = '${a}',
map = { a: '23' },
newStr;
newStr = myutils.expandVar(str, map, true);
should.exist(newStr);
newStr.should.be.equal(23);
});
});
describe('When there is a variable which is a null', function() {
it('should return the null', function() {
var str = '${a}',
map = { a: null },
newStr;
newStr = myutils.expandVar(str, map, true);
should.equal(newStr, null);
});
});
describe('When there is a variable which is a string null', function() {
it('should return the null', function() {
var str = '${a}',
map = { a: 'null' },
newStr;
newStr = myutils.expandVar(str, map, true);
should.equal(newStr, null);
});
});
describe('When there is a variable which is a string', function() {
it('should return the string', function() {
var str = '${a}',
map = { a: 'boniato' },
newStr;
newStr = myutils.expandVar(str, map, true);
should.exist(newStr);
newStr.should.be.equal('boniato');
});
});
describe('When there is not variable ', function() {
it('should return the string', function() {
var str = '${a}',
map = { b: 'boniato' },
newStr;
newStr = myutils.expandVar(str, map, true);
should.equal(newStr, null);
});
});
describe('When there is not some variables', function() {
it('should return the string', function() {
var str = '${a} and ${b}',
map = { b: 'boniato' },
newStr;
newStr = myutils.expandVar(str, map, true);
should.exist(newStr);
newStr.should.be.equal('null and boniato');
});
});
});
describe('#RequestHelper()', function() {
describe('When there is a network problem', function() {
Expand Down

0 comments on commit e52ff91

Please sign in to comment.