diff --git a/lib/jsonapter.js b/lib/jsonapter.js index 344cce5..f30bffc 100644 --- a/lib/jsonapter.js +++ b/lib/jsonapter.js @@ -10,7 +10,7 @@ var prototype = { return _.get(input, dataKey, null); } }, - paramKeyToInput: function (input, paramKey, params) { + paramKeyToInput: function (params, paramKey) { return _.get(params, paramKey, null); }, genericKeyArrayToInput: function (input, keyArray, fn) { @@ -39,9 +39,9 @@ var prototype = { }, evaluateParamKey: function (input, paramKey, params) { if (Array.isArray(paramKey)) { - return this.paramKeyArrayToInput(input, paramKey); + return this.paramKeyArrayToInput(params, paramKey); } else { - return this.paramKeyToInput(input, paramKey, params); + return this.paramKeyToInput(params, paramKey, params); } }, evaluateValue: function (value, input, params) { @@ -86,7 +86,7 @@ var prototype = { hasValue = true; } else { var expr = that.validatePruneValue(value); - if (!_.contains(that.options.pruneValues, expr) || (content[key].default !== null && content[key].default !== undefined)) { + if (!_.includes(that.options.pruneValues, expr) || (content[key].default !== null && content[key].default !== undefined)) { if (template.ignoreDeep) { r[key] = value; } else { diff --git a/package.json b/package.json index db4c043..18ea98f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jsonapter", - "version": "0.0.6", + "version": "0.1.0", "description": "Template based JSON to JSON transformer", "main": "./index.js", "directories": { @@ -19,7 +19,7 @@ "node": ">= 0.10.0" }, "dependencies": { - "lodash": "^3.9.3" + "lodash": "^4.15.0" }, "devDependencies": { "chai": "^3.0.0", diff --git a/test/test-paramKey.js b/test/test-paramKey.js index fecc325..ef16a07 100644 --- a/test/test-paramKey.js +++ b/test/test-paramKey.js @@ -6,11 +6,17 @@ var json2json = require('../index'); var case_0 = require('./test_cases/case-paramKey-0'); var case_1 = require('./test_cases/case-paramKey-1'); +var case_2 = require('./test_cases/case-paramKey-2'); var params = { timestamp: "2016-08-24T15:38:07-05:00" }; +var params2 = { + timestamp2: "2016-08-24T15:38:07-06:00", + timestamp3: "2016-08-24T15:38:07-07:00", +}; + var expect = chai.expect; describe('paramKey', function () { @@ -34,4 +40,12 @@ describe('paramKey', function () { } }); + it('case-paramKey-2: paramKey ', function () { + var template = case_2.template; + var n = case_2.inputs.length; + for (var i = 0; i < n; ++i) { + var actual = engine.run(template, case_1.inputs[i], params2); + expect(actual).to.deep.equal(case_2.expecteds[i]); + } + }); }); diff --git a/test/test_cases/case-paramKey-2.js b/test/test_cases/case-paramKey-2.js new file mode 100644 index 0000000..219178b --- /dev/null +++ b/test/test_cases/case-paramKey-2.js @@ -0,0 +1,28 @@ +"use strict"; + +exports.template = { + arrayContent: [{ + content: { + created: { + paramKey: ['timestamp', 'timestamp2'] + } + } + }, { + content: { + updated: { + paramKey: 'timestamp3' + } + } + }] +}; + +exports.inputs = []; +exports.expecteds = []; + +exports.inputs[0] = {}; + +exports.expecteds[0] = [{ + created: '2016-08-24T15:38:07-06:00' +}, { + updated: '2016-08-24T15:38:07-07:00' +}];