From 3f8cda81a93193a50b4a6b147a158e9d4f92a4b7 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Tue, 21 Jul 2020 14:27:13 -0500 Subject: [PATCH] test: Fix mocha/no-skipped-tests --- .eslintrc.js | 3 - test/functional/ProgramCallFunctional.js | 37 +++--- test/functional/checkObjectExists.js | 50 +++++---- .../deprecated/iDataQueueFunctional.js | 2 +- test/functional/deprecated/iPgmFunctional.js | 35 +++--- test/functional/deprecated/iSqlFunctional.js | 101 +++++++++-------- test/functional/deprecated/iWorkFunctional.js | 2 +- test/functional/iDataQueueFunctional.js | 4 +- test/functional/iSqlFunctional.js | 105 +++++++++--------- test/functional/iWorkFunctional.js | 2 +- 10 files changed, 181 insertions(+), 160 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 36997421..a7ec0702 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -28,9 +28,6 @@ module.exports = { // and https://github.com/airbnb/javascript/issues/433 'func-names': 'off', 'prefer-arrow-callback': 'off', - - // The following rules cause problems for our existing tests, so they are disabled for now: - 'mocha/no-skipped-tests': 'off', }, }, ], diff --git a/test/functional/ProgramCallFunctional.js b/test/functional/ProgramCallFunctional.js index ec0f7962..29883bb1 100644 --- a/test/functional/ProgramCallFunctional.js +++ b/test/functional/ProgramCallFunctional.js @@ -19,6 +19,7 @@ const { expect } = require('chai'); const { parseString } = require('xml2js'); const { ProgramCall, Connection } = require('../../lib/itoolkit'); const { config, printConfig } = require('./config'); +const { checkObjectExists } = require('./checkObjectExists'); describe('ProgramCall Functional Tests', function () { @@ -81,25 +82,29 @@ describe('ProgramCall Functional Tests', function () { }); }); - describe.skip('addReturn', function () { + describe('addReturn', function () { // ZZSRV6 program requires XMLSERVICE built with tests - // Skip for now, we need to add before hook to check ZZSRV6 is available - it.skip('calls ZZVARY4 and checks the return value', function (done) { - const connection = new Connection(config); + // See https://github.com/IBM/xmlservice#building-from-source + it('calls ZZVARY4 and checks the return value', function (done) { + checkObjectExists(config, { name: 'ZZSRV6', type: '*SRVPGM', lib: 'XMLSERVICE' }, (error) => { + if (error) { + this.skip(); + } + const connection = new Connection(config); - const program = new ProgramCall('ZZSRV6', { lib: 'XMLSERVICE', func: 'ZZVARY4' }); + const program = new ProgramCall('ZZSRV6', { lib: 'XMLSERVICE', func: 'ZZVARY4' }); - program.addParam({ type: '10A', varying: '4', value: 'Gill' }); - const testValue = 'NEW_NAME'; - program.addReturn('0', '20A', { varying: '4', name: testValue }); - connection.add(program); - connection.run((error, xmlOut) => { - expect(error).to.equal(null); - parseString(xmlOut, (parseError, result) => { - expect(parseError).to.equal(null); - expect(result.myscript.pgm[0].success[0]).to.include('+++ success'); - expect(result.myscript.pgm[0].return[0].data[0]._).to.equal('my name is Gill'); - done(); + program.addParam({ type: '10A', varying: '4', value: 'Gill' }); + program.addReturn({ value: '0', type: '20A', varying: '4' }); + connection.add(program); + connection.run((runError, xmlOut) => { + expect(runError).to.equal(null); + parseString(xmlOut, (parseError, result) => { + expect(parseError).to.equal(null); + expect(result.myscript.pgm[0].success[0]).to.include('+++ success'); + expect(result.myscript.pgm[0].return[0].data[0]._).to.equal('my name is Gill'); + done(); + }); }); }); }); diff --git a/test/functional/checkObjectExists.js b/test/functional/checkObjectExists.js index c383a7b8..85fe8950 100644 --- a/test/functional/checkObjectExists.js +++ b/test/functional/checkObjectExists.js @@ -1,7 +1,3 @@ -const lib = 'NODETKTEST'; -const createLib = `CRTLIB LIB(${lib}) TYPE(*TEST) TEXT('Used to test Node.js toolkit')`; -const findLib = `SELECT SCHEMA_NAME FROM qsys2.sysschemas WHERE SCHEMA_NAME = '${lib}'`; - function checkObjectExistsSSH(config, object = {}, callback) { // ssh2 is an optional dependency, since users may not use this transport // thus we can't globally require it @@ -9,8 +5,8 @@ function checkObjectExistsSSH(config, object = {}, callback) { const { Client } = require('ssh2'); const client = new Client(); - const checkLibCommand = `system 'CHKOBJ OBJ(QSYS/${lib}) OBJTYPE(*LIB)'`; - const checkObjectCommand = `system 'CHKOBJ OBJ(${lib}/${object.name}) OBJTYPE(${object.type})'`; + const checkLibCommand = `system 'CHKOBJ OBJ(QSYS/${object.lib}) OBJTYPE(*LIB)'`; + const checkObjectCommand = `system 'CHKOBJ OBJ(${object.lib}/${object.name}) OBJTYPE(${object.type})'`; // if client.connect has an error it will be handled here client.on('error', (error) => { @@ -20,7 +16,7 @@ function checkObjectExistsSSH(config, object = {}, callback) { client.on('ready', () => { client.exec(checkLibCommand, (checkLibError, checkLibStream) => { /* eslint-disable no-console */ - console.log(`executing ${checkLibCommand}`); + if (config.verbose) { console.log(`executing ${checkLibCommand}`); } if (checkLibError) { callback(checkLibError, false); return; @@ -31,7 +27,7 @@ function checkObjectExistsSSH(config, object = {}, callback) { checkLibStream.on('exit', (checkLibCode) => { if (checkLibCode !== 0) { if (config.verbose) { console.log(`Command exited abnormally with code: ${checkLibCode}`); } - const libError = new Error(`${lib} lib was not found!\nCreate it by running: ${createLib}`); + const libError = new Error(`${object.lib} lib was not found!\nCreate it by running: ${object.createLib}`); client.end(); client.destroy(); callback(libError, false); @@ -82,7 +78,7 @@ function checkObjectExistsODBC(config, object = {}, callback) { callback(connectError, false); return; } - connection.query(findLib, (findLibError, libResult) => { + connection.query(object.findLib, (findLibError, libResult) => { if (findLibError) { callback(findLibError, false); return; @@ -91,7 +87,7 @@ function checkObjectExistsODBC(config, object = {}, callback) { console.log('find lib result set: ', libResult); } if (!libResult.length) { - const libError = new Error(`${lib} lib was not found!\nCreate it by running:${createLib}`); + const libError = new Error(`${object.lib} lib was not found!\nCreate it by running:${object.createLib}`); callback(libError, false); return; } @@ -126,7 +122,7 @@ function checkObjectExistsIDB(config, object = {}, callback) { connection.conn('*LOCAL'); const statement = new dbstmt(connection); - statement.exec(findLib, (libResult, error) => { + statement.exec(object.findLib, (libResult, error) => { if (error) { callback(error, null); return; @@ -135,7 +131,7 @@ function checkObjectExistsIDB(config, object = {}, callback) { console.log('find lib result set: ', libResult); } if (!libResult.length) { - const libError = new Error(`${lib} lib was not found! Create it by running: ${createLib}`); + const libError = new Error(`${object.lib} lib was not found! Create it by running: ${object.createLib}`); callback(libError, null); return; } @@ -161,18 +157,30 @@ function checkObjectExistsIDB(config, object = {}, callback) { }); } -function checkObjectExists(config, name, type, callback) { - const object = { type }; +function checkObjectExists(config, obj = {}, callback) { + const object = obj; + + if (!object.type) { + callback(Error('Object type must be defined'), null); + return; + } + + if (!object.name) { + callback(Error('Object name must be defined'), null); + return; + } + + object.lib = object.lib || 'NODETKTEST'; - if (type === '*DTAARA') { - object.name = name; - object.createObject = `CRTDTAARA DTAARA(${lib}/${name}) TYPE(*CHAR) TEXT('TEST DATA AREA FOR NODE TOOLKIT') VALUE('Hello From Test Data Area!')`; - } else if (type === '*DTAQ') { - object.name = name; - object.createObject = `CRTDTAQ DTAQ(${lib}/${name}) MAXLEN(100) AUT(*EXCLUDE) TEXT('TEST DQ FOR NODE TOOLKIT TESTS')`; + if (object.type === '*DTAARA') { + object.createObject = `CRTDTAARA DTAARA(${object.lib}/${object.name}) TYPE(*CHAR) TEXT('TEST DATA AREA FOR NODE TOOLKIT') VALUE('Hello From Test Data Area!')`; + } else if (object.type === '*DTAQ') { + object.createObject = `CRTDTAQ DTAQ(${object.lib}/${object.name}) MAXLEN(100) AUT(*EXCLUDE) TEXT('TEST DQ FOR NODE TOOLKIT TESTS')`; } - object.findObject = `SELECT OBJNAME FROM TABLE (QSYS2.OBJECT_STATISTICS('${lib}', '${type}')) AS X WHERE OBJNAME = '${name}'`; + object.findObject = `SELECT OBJNAME FROM TABLE (QSYS2.OBJECT_STATISTICS('${object.lib}', '${object.type}')) AS X WHERE OBJNAME = '${object.name}'`; + object.createLib = `CRTLIB LIB(${object.lib}) TYPE(*TEST) TEXT('Used to test Node.js toolkit')`; + object.findlib = `SELECT SCHEMA_NAME FROM qsys2.sysschemas WHERE SCHEMA_NAME = '${object.lib}'`; // eslint-disable-next-line no-param-reassign config.transportOptions.verbose = config.verbose; diff --git a/test/functional/deprecated/iDataQueueFunctional.js b/test/functional/deprecated/iDataQueueFunctional.js index eb10a070..de0e7129 100644 --- a/test/functional/deprecated/iDataQueueFunctional.js +++ b/test/functional/deprecated/iDataQueueFunctional.js @@ -47,7 +47,7 @@ const lib = 'NODETKTEST'; const dqName = 'TESTQ'; describe('iDataQueue Functional Tests', function () { before('check if data queue exists for tests', function (done) { printConfig(); - checkObjectExists(config, dqName, '*DTAQ', (error) => { + checkObjectExists(config, { name: dqName, type: '*DTAQ' }, (error) => { if (error) { throw error; } done(); }); diff --git a/test/functional/deprecated/iPgmFunctional.js b/test/functional/deprecated/iPgmFunctional.js index 74ab522d..b6f78b02 100644 --- a/test/functional/deprecated/iPgmFunctional.js +++ b/test/functional/deprecated/iPgmFunctional.js @@ -21,6 +21,7 @@ const { expect } = require('chai'); const { parseString } = require('xml2js'); const { iPgm, iConn } = require('../../../lib/itoolkit'); const { config, printConfig } = require('../config'); +const { checkObjectExists } = require('../checkObjectExists'); // deprecated tests are in place to test compatability using deprecated classes and functions // these tests use deprecated iConn Class to create a connnection @@ -79,24 +80,28 @@ describe('iPgm Functional Tests', function () { }); }); - describe.skip('addReturn', function () { + describe('addReturn', function () { // ZZSRV6 program requires XMLSERVICE built with tests - // Skip for now, we need to add before hook to check if ZZSRV6 is available - it.skip('calls ZZVARY4 and checks the return value', function (done) { - const connection = new iConn(database, username, password, restOptions); + // See https://github.com/IBM/xmlservice#building-from-source + it('calls ZZVARY4 and checks the return value', function (done) { + checkObjectExists(config, { name: 'ZZSRV6', type: '*SRVPGM', lib: 'XMLSERVICE' }, (error) => { + if (error) { + this.skip(); + } + const connection = new iConn(database, username, password, restOptions); - const program = new iPgm('ZZSRV6', { lib: 'XMLSERVICE', func: 'ZZVARY4' }); + const program = new iPgm('ZZSRV6', { lib: 'XMLSERVICE', func: 'ZZVARY4' }); - program.addParam('Gill', '10A', { varying: '4' }); - const testValue = 'NEW_NAME'; - program.addReturn('0', '20A', { varying: '4', name: testValue }); - connection.add(program); - connection.run((xmlOut) => { - parseString(xmlOut, (parseError, result) => { - expect(parseError).to.equal(null); - expect(result.myscript.pgm[0].success[0]).to.include('+++ success'); - expect(result.myscript.pgm[0].return[0].data[0]._).to.equal('my name is Gill'); - done(); + program.addParam('Gill', '10A', { varying: '4' }); + program.addReturn('0', '20A', { varying: '4' }); + connection.add(program); + connection.run((xmlOut) => { + parseString(xmlOut, (parseError, result) => { + expect(parseError).to.equal(null); + expect(result.myscript.pgm[0].success[0]).to.include('+++ success'); + expect(result.myscript.pgm[0].return[0].data[0]._).to.equal('my name is Gill'); + done(); + }); }); }); }); diff --git a/test/functional/deprecated/iSqlFunctional.js b/test/functional/deprecated/iSqlFunctional.js index 60d8b5d0..6231741f 100644 --- a/test/functional/deprecated/iSqlFunctional.js +++ b/test/functional/deprecated/iSqlFunctional.js @@ -401,53 +401,56 @@ describe('iSql Functional Tests', function () { }); }); - describe.skip('special', function () { - // TODO: find passing case - // Below test fails with error code 9- argument value not valid - it.skip('returns meta data for special columns', function (done) { - // [catalog, schema, table, row | transaction |session, no | nullable] - const connection = new iConn(database, username, password, restOptions); - - const sql = new iSql(); - - sql.special(['', 'QUSRSYS', 'QASZRAIRX', 'row', 'no'], { error: 'on' }); - connection.add(sql.toXML()); - connection.debug(true); - connection.run((xmlOut) => { - parseString(xmlOut, (parseError, result) => { - expect(parseError).to.equal(null); - // TODO add more assertions - expect(result).to.be.an('object'); - done(); - }); - }); - }); - }); - - describe.skip('rowCount', function () { - // Skip for now need to create a table for this test to insert to. - it.skip('returns the number of rows affected by statement', function (done) { - const connection = new iConn(database, username, password, restOptions); - - const sql = new iSql(); - - const insert = 'INSERT INTO QIWS.QCUSTCDT (CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) ' - + 'VALUES (8798,\'TURNER\',\'TT\',\'MAIN\',\'NYC\',\'NY\',10001, 500, 3, 40.00, 0.00) with NONE'; - - sql.addQuery(insert); - sql.rowCount(); - sql.free(); - connection.add(sql.toXML()); - connection.run((xmlOut) => { - parseString(xmlOut, (parseError, result) => { - const sqlNode = result.myscript.sql[0]; - expect(parseError).to.equal(null); - expect(sqlNode.query[0].success[0]).to.include('+++ success'); - expect(sqlNode.free[0].success[0]).to.include('+++ success'); - expect(sqlNode.rowcount[0]._).to.equal('1'); - done(); - }); - }); - }); - }); + // TODO: Create test cases for the following + + // describe.skip('special', function () { + // // Below test fails with error code 9- argument value not valid + // it.skip('returns meta data for special columns', function (done) { + // // [catalog, schema, table, row | transaction |session, no | nullable] + // const connection = new iConn(database, username, password, restOptions); + + // const sql = new iSql(); + + // sql.special(['', 'QUSRSYS', 'QASZRAIRX', 'row', 'no'], { error: 'on' }); + // connection.add(sql.toXML()); + // connection.debug(true); + // connection.run((xmlOut) => { + // parseString(xmlOut, (parseError, result) => { + // expect(parseError).to.equal(null); + // // TODO add more assertions + // expect(result).to.be.an('object'); + // done(); + // }); + // }); + // }); + // }); + + // describe.skip('rowCount', function () { + // // Skip for now need to create a table for this test to insert to. + // it.skip('returns the number of rows affected by statement', function (done) { + // const connection = new iConn(database, username, password, restOptions); + + // const sql = new iSql(); + + // const insert = 'INSERT INTO QIWS.QCUSTCDT + // + (CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) ' + // + 'VALUES (8798,\'TURNER\',\'TT\',\'MAIN\',\'NYC\',\'NY\',10001, 500, 3, 40.00, 0.00) + // + with NONE'; + + // sql.addQuery(insert); + // sql.rowCount(); + // sql.free(); + // connection.add(sql.toXML()); + // connection.run((xmlOut) => { + // parseString(xmlOut, (parseError, result) => { + // const sqlNode = result.myscript.sql[0]; + // expect(parseError).to.equal(null); + // expect(sqlNode.query[0].success[0]).to.include('+++ success'); + // expect(sqlNode.free[0].success[0]).to.include('+++ success'); + // expect(sqlNode.rowcount[0]._).to.equal('1'); + // done(); + // }); + // }); + // }); + // }); }); diff --git a/test/functional/deprecated/iWorkFunctional.js b/test/functional/deprecated/iWorkFunctional.js index 9e767c96..45c74094 100644 --- a/test/functional/deprecated/iWorkFunctional.js +++ b/test/functional/deprecated/iWorkFunctional.js @@ -211,7 +211,7 @@ describe('iWork Functional Tests', function () { describe('getDataArea', function () { it('returns contents of a data area', function (done) { - checkObjectExists(config, 'TESTDA', '*DTAARA', (error) => { + checkObjectExists(config, { name: 'TESTDA', type: '*DTAARA' }, (error) => { if (error) { throw error; } const connection = new iConn(database, username, password, restOptions); diff --git a/test/functional/iDataQueueFunctional.js b/test/functional/iDataQueueFunctional.js index 3ac0cf84..c650c4ca 100644 --- a/test/functional/iDataQueueFunctional.js +++ b/test/functional/iDataQueueFunctional.js @@ -30,10 +30,10 @@ describe('DataQueue Functional Tests', function () { before('check if data queue exists for tests', function (done) { printConfig(); - checkObjectExists(config, dqName, '*DTAQ', (error) => { + checkObjectExists(config, { name: dqName, type: '*DTAQ' }, (error) => { if (error) { throw error; } - checkObjectExists(config, dqName2, '*DTAQ', (error2) => { + checkObjectExists(config, { name: dqName2, type: '*DTAQ' }, (error2) => { if (error2) { throw error2; } done(); }); diff --git a/test/functional/iSqlFunctional.js b/test/functional/iSqlFunctional.js index d2debda0..f11e7e74 100644 --- a/test/functional/iSqlFunctional.js +++ b/test/functional/iSqlFunctional.js @@ -394,55 +394,58 @@ describe('iSql Functional Tests', function () { }); }); - describe.skip('special', function () { - // TODO: find passing case - // Below test fails with error code 9- argument value not valid - it.skip('returns meta data for special columns', function (done) { - // [catalog, schema, table, row | transaction |session, no | nullable] - const connection = new Connection(config); - - const sql = new iSql(); - - sql.special(['', 'QUSRSYS', 'QASZRAIRX', 'row', 'no'], { error: 'on' }); - connection.add(sql.toXML()); - connection.debug(true); - connection.run((error, xmlOut) => { - expect(error).to.equal(null); - parseString(xmlOut, (parseError, result) => { - expect(parseError).to.equal(null); - // TODO add more assertions - expect(result).to.be.an('object'); - done(); - }); - }); - }); - }); - - describe.skip('rowCount', function () { - // Skip for now need to create a table for this test to insert to. - it.skip('returns the number of rows affected by statement', function (done) { - const connection = new Connection(config); - - const sql = new iSql(); - - const insert = 'INSERT INTO QIWS.QCUSTCDT (CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) ' - + 'VALUES (8798,\'TURNER\',\'TT\',\'MAIN\',\'NYC\',\'NY\',10001, 500, 3, 40.00, 0.00) with NONE'; - - sql.addQuery(insert); - sql.rowCount(); - sql.free(); - connection.add(sql.toXML()); - connection.run((error, xmlOut) => { - expect(error).to.equal(null); - parseString(xmlOut, (parseError, result) => { - const sqlNode = result.myscript.sql[0]; - expect(parseError).to.equal(null); - expect(sqlNode.query[0].success[0]).to.include('+++ success'); - expect(sqlNode.free[0].success[0]).to.include('+++ success'); - expect(sqlNode.rowcount[0]._).to.equal('1'); - done(); - }); - }); - }); - }); + // TODO: Create test cases for the following + + // describe.skip('special', function () { + // // Below test fails with error code 9- argument value not valid + // it.skip('returns meta data for special columns', function (done) { + // // [catalog, schema, table, row | transaction |session, no | nullable] + // const connection = new Connection(config); + + // const sql = new iSql(); + + // sql.special(['', 'QUSRSYS', 'QASZRAIRX', 'row', 'no'], { error: 'on' }); + // connection.add(sql.toXML()); + // connection.debug(true); + // connection.run((error, xmlOut) => { + // expect(error).to.equal(null); + // parseString(xmlOut, (parseError, result) => { + // expect(parseError).to.equal(null); + // // TODO add more assertions + // expect(result).to.be.an('object'); + // done(); + // }); + // }); + // }); + // }); + + // describe.skip('rowCount', function () { + // // Skip for now need to create a table for this test to insert to. + // it.skip('returns the number of rows affected by statement', function (done) { + // const connection = new Connection(config); + + // const sql = new iSql(); + + // const insert = 'INSERT INTO QIWS.QCUSTCDT + // +(CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) ' + // + 'VALUES (8798,\'TURNER\',\'TT\',\'MAIN\',\'NYC\',\'NY\',10001, 500, 3, 40.00, 0.00) + // + with NONE'; + + // sql.addQuery(insert); + // sql.rowCount(); + // sql.free(); + // connection.add(sql.toXML()); + // connection.run((error, xmlOut) => { + // expect(error).to.equal(null); + // parseString(xmlOut, (parseError, result) => { + // const sqlNode = result.myscript.sql[0]; + // expect(parseError).to.equal(null); + // expect(sqlNode.query[0].success[0]).to.include('+++ success'); + // expect(sqlNode.free[0].success[0]).to.include('+++ success'); + // expect(sqlNode.rowcount[0]._).to.equal('1'); + // done(); + // }); + // }); + // }); + // }); }); diff --git a/test/functional/iWorkFunctional.js b/test/functional/iWorkFunctional.js index 71214f9b..8cceddbf 100644 --- a/test/functional/iWorkFunctional.js +++ b/test/functional/iWorkFunctional.js @@ -193,7 +193,7 @@ describe('iWork Functional Tests', function () { describe('getDataArea', function () { it('returns contents of a data area', function (done) { - checkObjectExists(config, 'TESTDA', '*DTAARA', (error) => { + checkObjectExists(config, { name: 'TESTDA', type: '*DTAARA' }, (error) => { if (error) { throw error; } const connection = new Connection(config);