From 33e7970faf5f995a26f70184962f7eb777e070fd Mon Sep 17 00:00:00 2001 From: Ricardo Brambila Date: Tue, 12 Nov 2019 10:29:28 -0300 Subject: [PATCH] fix(utils): uses a recursive convertToPSParam to get converted types inside array --- lib/utils.js | 2 +- test/others.spec.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index eaedd17..1038c7a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -59,7 +59,7 @@ const convertToPSParam = val => { case 'Number': return val; case 'Array': - return val; + return val.map(convertToPSParam); case 'Object': return `@${JSON.stringify(val).replace(/:/g, '=').replace(/,/g, ';')}`; case 'Boolean': diff --git a/test/others.spec.js b/test/others.spec.js index 31e788e..6aa1837 100644 --- a/test/others.spec.js +++ b/test/others.spec.js @@ -14,6 +14,7 @@ const { convertToPSParam, convertToPSOption, } = require('../lib/utils'); + const { PS_PROC_ERROR, PS_ARG_MISS_ERROR, @@ -44,6 +45,15 @@ describe('Utils', () => { }); describe('convert', () => { + it('convert an array to a PS param', () => { + const param = [true, "String with spaces", { key: 123 }]; + const convertedParam = convertToPSParam(param); + + expect(convertedParam[0]).to.equal("$True"); + expect(convertedParam[1]).to.equal('"String with spaces"'); + expect(convertedParam[2]).to.equal('@{"key"=123}'); + }); + it('convert a JS param to a PS param'); it('convert a JS option to a PS option'); });