Skip to content

test: Fix mocha/no-skipped-tests #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
],
Expand Down
37 changes: 21 additions & 16 deletions test/functional/ProgramCallFunctional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();
});
});
});
});
Expand Down
50 changes: 29 additions & 21 deletions test/functional/checkObjectExists.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
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
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
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) => {
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion test/functional/deprecated/iDataQueueFunctional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
35 changes: 20 additions & 15 deletions test/functional/deprecated/iPgmFunctional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
});
});
});
Expand Down
101 changes: 52 additions & 49 deletions test/functional/deprecated/iSqlFunctional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// });
// });
// });
// });
});
2 changes: 1 addition & 1 deletion test/functional/deprecated/iWorkFunctional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions test/functional/iDataQueueFunctional.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Loading