From 076ea5372a14bb69bbf88dd5c0b51425de4ca7f5 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Mon, 30 Mar 2020 18:18:21 -0500 Subject: [PATCH] feat: Add Support for DS within return node --- lib/Deprecated.js | 23 +++++++++++++++-------- lib/ProgramCall.js | 26 ++++++++++---------------- test/unit/ProgamCallUnit.js | 30 +++++++++++++++++++++++++----- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/lib/Deprecated.js b/lib/Deprecated.js index 5fd6da4e..24fe6644 100644 --- a/lib/Deprecated.js +++ b/lib/Deprecated.js @@ -109,18 +109,25 @@ class iPgm { /** * @description adds a return element to the program XML - * @param {string} data + * @param {string} value * @param {string} type * @param {object} [options] */ - addReturn(data, type = '1024a', options) { - if (!type) { - iPgmDeprecate('defaulting return type to 1024a has been deprecated. You should specify a type instead.'); - // eslint-disable-next-line no-param-reassign - type = '1024a'; + addReturn(value, type = '1024a', options) { + const data = {}; + data.type = type; + data.value = value; + if (!data.type) { + iPgmDeprecate('defaulting return data type to 1024a has been deprecated. You should specify a type instead.'); + data.type = '1024a'; } - iPgmDeprecate('As of v1.0, \'iPgm.addReturn()\' is deprecated. Please use \'ProgramCall.addParam()\' instead.'); - return this.ProgramCall.addReturn(data, type, options); + + if (typeof options === 'object') { // options + Object.keys(options).forEach((key) => { + data[key] = options[key]; + }); + } + return this.ProgramCall.addReturn(data); } /** diff --git a/lib/ProgramCall.js b/lib/ProgramCall.js index ebf17379..e3d540bf 100644 --- a/lib/ProgramCall.js +++ b/lib/ProgramCall.js @@ -92,25 +92,19 @@ class ProgramCall { /** * @description adds a return element to the program XML - * @param {string} data - * @param {string} type - * @param {object} [options] + * @param {object} data */ - addReturn(data, type, options = null) { - if (!type) { - throw new Error('Specifying the return type is required.'); + addReturn(data = {}) { + if (typeof data !== 'object') { + throw new Error('Expected the first parameter to be an object'); } - this.xml += ''; - - if (options && typeof options === 'object') { - this.xml += ` { - this.xml += ` ${key}='${options[key]}'`; - }); - } else { - this.xml += `${data}`; + + this.xml += ''; + this.__addData__(data); + this.xml += ''; } /** diff --git a/test/unit/ProgamCallUnit.js b/test/unit/ProgamCallUnit.js index f9c91388..83ae43ed 100644 --- a/test/unit/ProgamCallUnit.js +++ b/test/unit/ProgamCallUnit.js @@ -139,7 +139,7 @@ describe('ProgramCall Class Unit Tests', () => { const pgm = new ProgramCall('MYPGM', { lib: 'MYLIB', func: 'MY_PROCEDURE' }); pgm.addParam({ value: '', type: '1A', by: 'val' }); - pgm.addReturn('', '2A', 'output'); + pgm.addReturn({ name: 'output', type: '2A', value: '' }); const lookAtXML = pgm.toXML(); expect(lookAtXML).to.match(//); @@ -156,7 +156,7 @@ describe('ProgramCall Class Unit Tests', () => { pgm.addParam({ name: 'inds', type: 'ds', by: 'val', fields: params, }); - pgm.addReturn('', '2A', { name: 'output' }); + pgm.addReturn({ name: 'output', type: '2A', value: '' }); const lookAtXML = pgm.toXML(); expect(lookAtXML).to.match(//); @@ -168,7 +168,7 @@ describe('ProgramCall Class Unit Tests', () => { pgm.addParam({ value: '', type: '1A', by: 'val', io: 'both', }); - pgm.addReturn('', '2A', { name: 'output' }); + pgm.addReturn({ name: 'output', type: '2A', value: '' }); const lookAtXML = pgm.toXML(); expect(lookAtXML).to.match(//); @@ -186,7 +186,7 @@ describe('ProgramCall Class Unit Tests', () => { pgm.addParam({ name: 'inds', type: 'ds', by: 'val', io: 'both', fields: params, }); - pgm.addReturn('', '2A', { name: 'output' }); + pgm.addReturn({ name: 'output', type: '2A', value: '' }); const lookAtXML = pgm.toXML(); expect(lookAtXML).to.match(//); @@ -204,12 +204,32 @@ describe('ProgramCall Class Unit Tests', () => { error: 'fast', }); - pgm.addReturn('0', '20A'); + pgm.addReturn({ type: '20A', value: '0' }); const expectedXML = '0'; expect(pgm.toXML()).to.equal(expectedXML); }); + + it('appends return with ds to pgm xml', () => { + const pgm = new ProgramCall('TEST'); + + const ds = { + name: 'test_ds', + type: 'ds', + io: 'out', + fields: [ + { type: '10i0', value: 0 }, + { type: '10A', value: '' }, + ], + }; + pgm.addReturn(ds); + + const expectedXML = "" + + "0"; + + expect(pgm.toXML()).to.equal(expectedXML); + }); }); });