diff --git a/lib/utils.js b/lib/utils.js index ce0d7bb7..aadb3e13 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -22,10 +22,7 @@ function arrayString(val) { if(i > 0) { result = result + ','; } - if(val[i] instanceof Date) { - result = result + JSON.stringify(val[i]); - } - else if(typeof val[i] === 'undefined') { + if(val[i] === null || typeof val[i] === 'undefined') { result = result + 'NULL'; } else if(Array.isArray(val[i])) { @@ -33,8 +30,7 @@ function arrayString(val) { } else { - result = result + - (val[i] === null ? 'NULL' : JSON.stringify(val[i])); + result = result + JSON.stringify(prepareValue(val[i])); } } result = result + '}'; diff --git a/test/unit/utils-tests.js b/test/unit/utils-tests.js index 45237a97..9cb2a3e4 100644 --- a/test/unit/utils-tests.js +++ b/test/unit/utils-tests.js @@ -95,9 +95,24 @@ test('prepareValue: string prepared properly', function() { assert.strictEqual(out, 'big bad wolf'); }); -test('prepareValue: array prepared properly', function() { +test('prepareValue: simple array prepared properly', function() { var out = utils.prepareValue([1, null, 3, undefined, [5, 6, "squ,awk"]]); - assert.strictEqual(out, '{1,NULL,3,NULL,{5,6,"squ,awk"}}'); + assert.strictEqual(out, '{"1",NULL,"3",NULL,{"5","6","squ,awk"}}'); +}); + +test('prepareValue: complex array prepared properly', function() { + var out = utils.prepareValue([{ x: 42 }, { y: 84 }]); + assert.strictEqual(out, '{"{\\"x\\":42}","{\\"y\\":84}"}'); +}); + +test('prepareValue: date array prepared properly', function() { + helper.setTimezoneOffset(-330); + + var date = new Date(2014, 1, 1, 11, 11, 1, 7); + var out = utils.prepareValue([date]); + assert.strictEqual(out, '{"2014-02-01T11:11:01.007+05:30"}'); + + helper.resetTimezoneOffset(); }); test('prepareValue: arbitrary objects prepared properly', function() {