Skip to content

Commit c794f94

Browse files
authored
Merge pull request #18 from amida-tech/params-test
lodash version bump + params array test/fix
2 parents b3fb423 + 2aa029e commit c794f94

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

lib/jsonapter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var prototype = {
1010
return _.get(input, dataKey, null);
1111
}
1212
},
13-
paramKeyToInput: function (input, paramKey, params) {
13+
paramKeyToInput: function (params, paramKey) {
1414
return _.get(params, paramKey, null);
1515
},
1616
genericKeyArrayToInput: function (input, keyArray, fn) {
@@ -39,9 +39,9 @@ var prototype = {
3939
},
4040
evaluateParamKey: function (input, paramKey, params) {
4141
if (Array.isArray(paramKey)) {
42-
return this.paramKeyArrayToInput(input, paramKey);
42+
return this.paramKeyArrayToInput(params, paramKey);
4343
} else {
44-
return this.paramKeyToInput(input, paramKey, params);
44+
return this.paramKeyToInput(params, paramKey, params);
4545
}
4646
},
4747
evaluateValue: function (value, input, params) {
@@ -86,7 +86,7 @@ var prototype = {
8686
hasValue = true;
8787
} else {
8888
var expr = that.validatePruneValue(value);
89-
if (!_.contains(that.options.pruneValues, expr) || (content[key].default !== null && content[key].default !== undefined)) {
89+
if (!_.includes(that.options.pruneValues, expr) || (content[key].default !== null && content[key].default !== undefined)) {
9090
if (template.ignoreDeep) {
9191
r[key] = value;
9292
} else {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonapter",
3-
"version": "0.0.6",
3+
"version": "0.1.0",
44
"description": "Template based JSON to JSON transformer",
55
"main": "./index.js",
66
"directories": {
@@ -19,7 +19,7 @@
1919
"node": ">= 0.10.0"
2020
},
2121
"dependencies": {
22-
"lodash": "^3.9.3"
22+
"lodash": "^4.15.0"
2323
},
2424
"devDependencies": {
2525
"chai": "^3.0.0",

test/test-paramKey.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ var json2json = require('../index');
66

77
var case_0 = require('./test_cases/case-paramKey-0');
88
var case_1 = require('./test_cases/case-paramKey-1');
9+
var case_2 = require('./test_cases/case-paramKey-2');
910

1011
var params = {
1112
timestamp: "2016-08-24T15:38:07-05:00"
1213
};
1314

15+
var params2 = {
16+
timestamp2: "2016-08-24T15:38:07-06:00",
17+
timestamp3: "2016-08-24T15:38:07-07:00",
18+
};
19+
1420
var expect = chai.expect;
1521

1622
describe('paramKey', function () {
@@ -34,4 +40,12 @@ describe('paramKey', function () {
3440
}
3541
});
3642

43+
it('case-paramKey-2: paramKey ', function () {
44+
var template = case_2.template;
45+
var n = case_2.inputs.length;
46+
for (var i = 0; i < n; ++i) {
47+
var actual = engine.run(template, case_1.inputs[i], params2);
48+
expect(actual).to.deep.equal(case_2.expecteds[i]);
49+
}
50+
});
3751
});

test/test_cases/case-paramKey-2.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
exports.template = {
4+
arrayContent: [{
5+
content: {
6+
created: {
7+
paramKey: ['timestamp', 'timestamp2']
8+
}
9+
}
10+
}, {
11+
content: {
12+
updated: {
13+
paramKey: 'timestamp3'
14+
}
15+
}
16+
}]
17+
};
18+
19+
exports.inputs = [];
20+
exports.expecteds = [];
21+
22+
exports.inputs[0] = {};
23+
24+
exports.expecteds[0] = [{
25+
created: '2016-08-24T15:38:07-06:00'
26+
}, {
27+
updated: '2016-08-24T15:38:07-07:00'
28+
}];

0 commit comments

Comments
 (0)