Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion test/functional/CommandCallFunctional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -61,13 +62,23 @@ 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);
// 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();
});
Expand Down
17 changes: 17 additions & 0 deletions test/functional/checkVersion.js
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 12 additions & 1 deletion test/functional/deprecated/commandsFunctional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
Expand Down