diff --git a/test/functional/CommandCallFunctional.js b/test/functional/CommandCallFunctional.js index 0a19d3fb..a62d4d96 100644 --- a/test/functional/CommandCallFunctional.js +++ b/test/functional/CommandCallFunctional.js @@ -17,8 +17,9 @@ const { expect } = require('chai'); const { parseString } = require('xml2js'); -const { CommandCall, Connection } = require('../../lib/itoolkit'); +const { CommandCall, Connection, ProgramCall } = require('../../lib/itoolkit'); const { config, printConfig } = require('./config'); +const { isQSHSupported } = require('./checkVersion'); describe('CommandCall Functional Tests', function () { @@ -61,6 +62,7 @@ describe('CommandCall Functional Tests', function () { describe('QSH command tests', function () { it('calls QSH command', function (done) { const connection = new Connection(config); + connection.add(new ProgramCall('MYPGMTOOLONG')); connection.add(new CommandCall({ command: 'system wrksyssts', type: 'qsh' })); connection.run((error, xmlOut) => { expect(error).to.equal(null); @@ -68,6 +70,15 @@ describe('CommandCall Functional Tests', function () { // but on error sh or qsh node will not have any inner data parseString(xmlOut, (parseError, result) => { expect(parseError).to.equal(null); + const match = result.myscript.pgm[0].version[0].match(/\d\.\d\.\d/); + if (!match) { + throw Error('Unable to determine XMLSERVICE version'); + } + if (!isQSHSupported(match[0])) { + // skip if QSH is unsupported + console.log(`XMLSERVICE version ${match[0]} does not support QSH`); + this.skip(); + } expect(result.myscript.qsh[0]._).to.match(/(System\sStatus\sInformation)/); done(); }); diff --git a/test/functional/checkVersion.js b/test/functional/checkVersion.js new file mode 100644 index 00000000..692403dd --- /dev/null +++ b/test/functional/checkVersion.js @@ -0,0 +1,17 @@ +/** + * Checks if XMLSERVICE version supports QSH. + * XMLSERVICE >= 1.9.8 supports QSH + * @param {string} version - expects sematic version i.e. 1.2.3 + */ +function isQSHSupported(version) { + // maps array of strings to numbers i.e. ['1', '2', '3'] -> [1, 2, 3] + const semver = version.split('.').map(Number); + if (semver[0] === 1 && semver[1] < 9) { + return false; + } if (semver[0] === 1 && semver[1] === 9 && semver[2] < 8) { + return false; + } + return true; +} + +module.exports.isQSHSupported = isQSHSupported; diff --git a/test/functional/deprecated/commandsFunctional.js b/test/functional/deprecated/commandsFunctional.js index 36e8815d..cfe65977 100644 --- a/test/functional/deprecated/commandsFunctional.js +++ b/test/functional/deprecated/commandsFunctional.js @@ -20,10 +20,11 @@ const { expect } = require('chai'); const { parseString } = require('xml2js'); const { - iCmd, iSh, iQsh, iConn, + iCmd, iSh, iQsh, iConn, iPgm, } = require('../../../lib/itoolkit'); const { config, printConfig } = require('../config'); +const { isQSHSupported } = require('../checkVersion'); // deprecated tests are in place to test compatability using deprecated classes and functions // these tests use deprecated iConn Class to create a connnection @@ -82,12 +83,22 @@ describe('iSh, iCmd, iQsh, Functional Tests', function () { describe('iQsh()', function () { it('calls QSH command', function (done) { const connection = new iConn(database, username, password, restOptions); + connection.add(new iPgm('MYPGMTOOLONG')); connection.add(iQsh('system wrksyssts')); connection.run((xmlOut) => { // xs does not return success property for sh or qsh command calls // but on error sh or qsh node will not have any inner data parseString(xmlOut, (parseError, result) => { expect(parseError).to.equal(null); + const match = result.myscript.pgm[0].version[0].match(/\d\.\d\.\d/); + if (!match) { + throw Error('Unable to determine XMLSERVICE version'); + } + if (!isQSHSupported(match[0])) { + // skip if QSH is unsupported + console.log(`XMLSERVICE version ${match[0]} does not support QSH`); + this.skip(); + } expect(result.myscript.qsh[0]._).to.match(/(System\sStatus\sInformation)/); done(); });