Skip to content

Commit 3e95388

Browse files
committed
test: Fix mocha/no-skipped-tests
1 parent 322dd42 commit 3e95388

10 files changed

+179
-156
lines changed

.eslintrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module.exports = {
2727
'prefer-arrow-callback': 'off',
2828

2929
// The following rules cause problems for our existing tests, so they are disabled for now:
30-
'mocha/no-skipped-tests': 'off',
3130
'mocha/no-hooks-for-single-case': 'off',
3231
'mocha/no-identical-title': 'off',
3332
},

test/functional/ProgramCallFunctional.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const { expect } = require('chai');
1919
const { parseString } = require('xml2js');
2020
const { ProgramCall, Connection } = require('../../lib/itoolkit');
2121
const { config, printConfig } = require('./config');
22+
const { checkObjectExists } = require('./checkObjectExists');
2223

2324

2425
describe('ProgramCall Functional Tests', function () {
@@ -81,25 +82,29 @@ describe('ProgramCall Functional Tests', function () {
8182
});
8283
});
8384

84-
describe.skip('Test ProgramCall()', function () {
85+
describe('Test ProgramCall()', function () {
8586
// ZZSRV6 program requires XMLSERVICE built with tests
8687
// Skip for now, we need to add before hook to check ZZSRV6 is available
87-
it.skip('Should be successful with addReturn arbitrary attribute specified', function (done) {
88-
const connection = new Connection(config);
88+
it('Should be successful with addReturn arbitrary attribute specified', function (done) {
89+
checkObjectExists(config, { name: 'ZZSRRV6', type: '*SRVPGM', lib: 'XMLSERVICE' }, (error) => {
90+
if (error) {
91+
this.skip();
92+
}
93+
const connection = new Connection(config);
8994

90-
const program = new ProgramCall('ZZSRV6', { lib: 'XMLSERVICE', func: 'ZZVARY4' });
95+
const program = new ProgramCall('ZZSRV6', { lib: 'XMLSERVICE', func: 'ZZVARY4'});
9196

92-
program.addParam({ type: '10A', varying: '4', value: 'Gill' });
93-
const testValue = 'NEW_NAME';
94-
program.addReturn('0', '20A', { varying: '4', name: testValue });
95-
connection.add(program);
96-
connection.run((error, xmlOut) => {
97-
expect(error).to.equal(null);
98-
parseString(xmlOut, (parseError, result) => {
99-
expect(parseError).to.equal(null);
100-
expect(result.myscript.pgm[0].success[0]).to.include('+++ success');
101-
expect(result.myscript.pgm[0].return[0].data[0]._).to.equal('my name is Gill');
102-
done();
97+
program.addParam({ type: '10A', varying: '4', value: 'Gill' });
98+
program.addReturn({ value: '0', type: '20A', varying: '4' });
99+
connection.add(program);
100+
connection.run((runError, xmlOut) => {
101+
expect(runError).to.equal(null);
102+
parseString(xmlOut, (parseError, result) => {
103+
expect(parseError).to.equal(null);
104+
expect(result.myscript.pgm[0].success[0]).to.include('+++ success');
105+
expect(result.myscript.pgm[0].return[0].data[0]._).to.equal('my name is Gill');
106+
done();
107+
});
103108
});
104109
});
105110
});

test/functional/checkObjectExists.js

+29-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
const lib = 'NODETKTEST';
2-
const createLib = `CRTLIB LIB(${lib}) TYPE(*TEST) TEXT('Used to test Node.js toolkit')`;
3-
const findLib = `SELECT SCHEMA_NAME FROM qsys2.sysschemas WHERE SCHEMA_NAME = '${lib}'`;
4-
51
function checkObjectExistsSSH(config, object = {}, callback) {
62
// ssh2 is an optional dependency, since users may not use this transport
73
// thus we can't globally require it
84
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
95
const { Client } = require('ssh2');
106

117
const client = new Client();
12-
const checkLibCommand = `system 'CHKOBJ OBJ(QSYS/${lib}) OBJTYPE(*LIB)'`;
13-
const checkObjectCommand = `system 'CHKOBJ OBJ(${lib}/${object.name}) OBJTYPE(${object.type})'`;
8+
const checkLibCommand = `system 'CHKOBJ OBJ(QSYS/${object.lib}) OBJTYPE(*LIB)'`;
9+
const checkObjectCommand = `system 'CHKOBJ OBJ(${object.lib}/${object.name}) OBJTYPE(${object.type})'`;
1410

1511
// if client.connect has an error it will be handled here
1612
client.on('error', (error) => {
@@ -20,7 +16,7 @@ function checkObjectExistsSSH(config, object = {}, callback) {
2016
client.on('ready', () => {
2117
client.exec(checkLibCommand, (checkLibError, checkLibStream) => {
2218
/* eslint-disable no-console */
23-
console.log(`executing ${checkLibCommand}`);
19+
if (config.verbose) { console.log(`executing ${checkLibCommand}`); }
2420
if (checkLibError) {
2521
callback(checkLibError, false);
2622
return;
@@ -31,7 +27,7 @@ function checkObjectExistsSSH(config, object = {}, callback) {
3127
checkLibStream.on('exit', (checkLibCode) => {
3228
if (checkLibCode !== 0) {
3329
if (config.verbose) { console.log(`Command exited abnormally with code: ${checkLibCode}`); }
34-
const libError = new Error(`${lib} lib was not found!\nCreate it by running: ${createLib}`);
30+
const libError = new Error(`${object.lib} lib was not found!\nCreate it by running: ${object.createLib}`);
3531
client.end();
3632
client.destroy();
3733
callback(libError, false);
@@ -82,7 +78,7 @@ function checkObjectExistsODBC(config, object = {}, callback) {
8278
callback(connectError, false);
8379
return;
8480
}
85-
connection.query(findLib, (findLibError, libResult) => {
81+
connection.query(object.findLib, (findLibError, libResult) => {
8682
if (findLibError) {
8783
callback(findLibError, false);
8884
return;
@@ -91,7 +87,7 @@ function checkObjectExistsODBC(config, object = {}, callback) {
9187
console.log('find lib result set: ', libResult);
9288
}
9389
if (!libResult.length) {
94-
const libError = new Error(`${lib} lib was not found!\nCreate it by running:${createLib}`);
90+
const libError = new Error(`${object.lib} lib was not found!\nCreate it by running:${object.createLib}`);
9591
callback(libError, false);
9692
return;
9793
}
@@ -126,7 +122,7 @@ function checkObjectExistsIDB(config, object = {}, callback) {
126122
connection.conn('*LOCAL');
127123
const statement = new dbstmt(connection);
128124

129-
statement.exec(findLib, (libResult, error) => {
125+
statement.exec(object.findLib, (libResult, error) => {
130126
if (error) {
131127
callback(error, null);
132128
return;
@@ -135,7 +131,7 @@ function checkObjectExistsIDB(config, object = {}, callback) {
135131
console.log('find lib result set: ', libResult);
136132
}
137133
if (!libResult.length) {
138-
const libError = new Error(`${lib} lib was not found! Create it by running: ${createLib}`);
134+
const libError = new Error(`${object.lib} lib was not found! Create it by running: ${object.createLib}`);
139135
callback(libError, null);
140136
return;
141137
}
@@ -161,18 +157,30 @@ function checkObjectExistsIDB(config, object = {}, callback) {
161157
});
162158
}
163159

164-
function checkObjectExists(config, name, type, callback) {
165-
const object = { type };
160+
function checkObjectExists(config, obj = {}, callback) {
161+
const object = obj;
162+
163+
if (!object.type) {
164+
callback(Error('Object type must be defined'), null);
165+
return;
166+
}
167+
168+
if (!object.name) {
169+
callback(Error('Object name must be defined'), null);
170+
return;
171+
}
172+
173+
object.lib = object.lib || 'NODETKTEST';
166174

167-
if (type === '*DTAARA') {
168-
object.name = name;
169-
object.createObject = `CRTDTAARA DTAARA(${lib}/${name}) TYPE(*CHAR) TEXT('TEST DATA AREA FOR NODE TOOLKIT') VALUE('Hello From Test Data Area!')`;
170-
} else if (type === '*DTAQ') {
171-
object.name = name;
172-
object.createObject = `CRTDTAQ DTAQ(${lib}/${name}) MAXLEN(100) AUT(*EXCLUDE) TEXT('TEST DQ FOR NODE TOOLKIT TESTS')`;
175+
if (object.type === '*DTAARA') {
176+
object.createObject = `CRTDTAARA DTAARA(${object.lib}/${object.name}) TYPE(*CHAR) TEXT('TEST DATA AREA FOR NODE TOOLKIT') VALUE('Hello From Test Data Area!')`;
177+
} else if (object.type === '*DTAQ') {
178+
object.createObject = `CRTDTAQ DTAQ(${object.lib}/${object.name}) MAXLEN(100) AUT(*EXCLUDE) TEXT('TEST DQ FOR NODE TOOLKIT TESTS')`;
173179
}
174180

175-
object.findObject = `SELECT OBJNAME FROM TABLE (QSYS2.OBJECT_STATISTICS('${lib}', '${type}')) AS X WHERE OBJNAME = '${name}'`;
181+
object.findObject = `SELECT OBJNAME FROM TABLE (QSYS2.OBJECT_STATISTICS('${object.lib}', '${object.type}')) AS X WHERE OBJNAME = '${object.name}'`;
182+
object.createLib = `CRTLIB LIB(${object.lib}) TYPE(*TEST) TEXT('Used to test Node.js toolkit')`;
183+
object.findlib = `SELECT SCHEMA_NAME FROM qsys2.sysschemas WHERE SCHEMA_NAME = '${object.lib}'`;
176184
// eslint-disable-next-line no-param-reassign
177185
config.transportOptions.verbose = config.verbose;
178186

test/functional/deprecated/iDataQueueFunctional.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const lib = 'NODETKTEST'; const dqName = 'TESTQ';
4747
describe('iDataQueue Functional Tests', function () {
4848
before('check if data queue exists for tests', function (done) {
4949
printConfig();
50-
checkObjectExists(config, dqName, '*DTAQ', (error) => {
50+
checkObjectExists(config, { name: dqName, type: '*DTAQ' }, (error) => {
5151
if (error) { throw error; }
5252
done();
5353
});

test/functional/deprecated/iPgmFunctional.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const { expect } = require('chai');
2121
const { parseString } = require('xml2js');
2222
const { iPgm, iConn } = require('../../../lib/itoolkit');
2323
const { config, printConfig } = require('../config');
24+
const { checkObjectExists } = require('../checkObjectExists');
2425

2526
// deprecated tests are in place to test compatability using deprecated classes and functions
2627
// these tests use deprecated iConn Class to create a connnection
@@ -79,24 +80,28 @@ describe('iPgm Functional Tests', function () {
7980
});
8081
});
8182

82-
describe.skip('Test iPgm()', function () {
83+
describe('Test iPgm()', function () {
8384
// ZZSRV6 program requires XMLSERVICE built with tests
8485
// Skip for now, we need to add before hook to check if ZZSRV6 is available
85-
it.skip('Should be successful with addReturn arbitrary attribute specified using', function (done) {
86-
const connection = new iConn(database, username, password, restOptions);
86+
it('Should be successful with addReturn arbitrary attribute specified using', function (done) {
87+
checkObjectExists(config, { name: 'ZZSRRV6', type: '*SRVPGM', lib: 'XMLSERVICE' }, (error) => {
88+
if (error) {
89+
this.skip();
90+
}
91+
const connection = new iConn(database, username, password, restOptions);
8792

88-
const program = new iPgm('ZZSRV6', { lib: 'XMLSERVICE', func: 'ZZVARY4' });
93+
const program = new iPgm('ZZSRV6', { lib: 'XMLSERVICE', func: 'ZZVARY4' });
8994

90-
program.addParam('Gill', '10A', { varying: '4' });
91-
const testValue = 'NEW_NAME';
92-
program.addReturn('0', '20A', { varying: '4', name: testValue });
93-
connection.add(program);
94-
connection.run((xmlOut) => {
95-
parseString(xmlOut, (parseError, result) => {
96-
expect(parseError).to.equal(null);
97-
expect(result.myscript.pgm[0].success[0]).to.include('+++ success');
98-
expect(result.myscript.pgm[0].return[0].data[0]._).to.equal('my name is Gill');
99-
done();
95+
program.addParam('Gill', '10A', { varying: '4' });
96+
program.addReturn('0', '20A', { varying: '4' });
97+
connection.add(program);
98+
connection.run((xmlOut) => {
99+
parseString(xmlOut, (parseError, result) => {
100+
expect(parseError).to.equal(null);
101+
expect(result.myscript.pgm[0].success[0]).to.include('+++ success');
102+
expect(result.myscript.pgm[0].return[0].data[0]._).to.equal('my name is Gill');
103+
done();
104+
});
100105
});
101106
});
102107
});

test/functional/deprecated/iSqlFunctional.js

+52-49
Original file line numberDiff line numberDiff line change
@@ -401,53 +401,56 @@ describe('iSql Functional Tests', function () {
401401
});
402402
});
403403

404-
describe.skip('special', function () {
405-
// TODO: find passing case
406-
// Below test fails with error code 9- argument value not valid
407-
it.skip('returns meta data for special columns', function (done) {
408-
// [catalog, schema, table, row | transaction |session, no | nullable]
409-
const connection = new iConn(database, username, password, restOptions);
410-
411-
const sql = new iSql();
412-
413-
sql.special(['', 'QUSRSYS', 'QASZRAIRX', 'row', 'no'], { error: 'on' });
414-
connection.add(sql.toXML());
415-
connection.debug(true);
416-
connection.run((xmlOut) => {
417-
parseString(xmlOut, (parseError, result) => {
418-
expect(parseError).to.equal(null);
419-
// TODO add more assertions
420-
expect(result).to.be.an('object');
421-
done();
422-
});
423-
});
424-
});
425-
});
426-
427-
describe.skip('rowCount', function () {
428-
// Skip for now need to create a table for this test to insert to.
429-
it.skip('returns the number of rows affected by statement', function (done) {
430-
const connection = new iConn(database, username, password, restOptions);
431-
432-
const sql = new iSql();
433-
434-
const insert = 'INSERT INTO QIWS.QCUSTCDT (CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) '
435-
+ 'VALUES (8798,\'TURNER\',\'TT\',\'MAIN\',\'NYC\',\'NY\',10001, 500, 3, 40.00, 0.00) with NONE';
436-
437-
sql.addQuery(insert);
438-
sql.rowCount();
439-
sql.free();
440-
connection.add(sql.toXML());
441-
connection.run((xmlOut) => {
442-
parseString(xmlOut, (parseError, result) => {
443-
const sqlNode = result.myscript.sql[0];
444-
expect(parseError).to.equal(null);
445-
expect(sqlNode.query[0].success[0]).to.include('+++ success');
446-
expect(sqlNode.free[0].success[0]).to.include('+++ success');
447-
expect(sqlNode.rowcount[0]._).to.equal('1');
448-
done();
449-
});
450-
});
451-
});
452-
});
404+
// TODO: Create test cases for the following
405+
406+
// describe.skip('special', function () {
407+
// // Below test fails with error code 9- argument value not valid
408+
// it.skip('returns meta data for special columns', function (done) {
409+
// // [catalog, schema, table, row | transaction |session, no | nullable]
410+
// const connection = new iConn(database, username, password, restOptions);
411+
412+
// const sql = new iSql();
413+
414+
// sql.special(['', 'QUSRSYS', 'QASZRAIRX', 'row', 'no'], { error: 'on' });
415+
// connection.add(sql.toXML());
416+
// connection.debug(true);
417+
// connection.run((xmlOut) => {
418+
// parseString(xmlOut, (parseError, result) => {
419+
// expect(parseError).to.equal(null);
420+
// // TODO add more assertions
421+
// expect(result).to.be.an('object');
422+
// done();
423+
// });
424+
// });
425+
// });
426+
// });
427+
428+
// describe.skip('rowCount', function () {
429+
// // Skip for now need to create a table for this test to insert to.
430+
// it.skip('returns the number of rows affected by statement', function (done) {
431+
// const connection = new iConn(database, username, password, restOptions);
432+
433+
// const sql = new iSql();
434+
435+
// const insert = 'INSERT INTO QIWS.QCUSTCDT
436+
// + (CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) '
437+
// + 'VALUES (8798,\'TURNER\',\'TT\',\'MAIN\',\'NYC\',\'NY\',10001, 500, 3, 40.00, 0.00)
438+
// + with NONE';
439+
440+
// sql.addQuery(insert);
441+
// sql.rowCount();
442+
// sql.free();
443+
// connection.add(sql.toXML());
444+
// connection.run((xmlOut) => {
445+
// parseString(xmlOut, (parseError, result) => {
446+
// const sqlNode = result.myscript.sql[0];
447+
// expect(parseError).to.equal(null);
448+
// expect(sqlNode.query[0].success[0]).to.include('+++ success');
449+
// expect(sqlNode.free[0].success[0]).to.include('+++ success');
450+
// expect(sqlNode.rowcount[0]._).to.equal('1');
451+
// done();
452+
// });
453+
// });
454+
// });
455+
// });
453456
});

test/functional/deprecated/iWorkFunctional.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('iWork Functional Tests', function () {
211211

212212
describe('getDataArea', function () {
213213
before('init lib, data area, and add data', function (done) {
214-
checkObjectExists(config, 'TESTDA', '*DTAARA', (error) => {
214+
checkObjectExists(config, { name: 'TESTDA', type: '*DTAARA' }, (error) => {
215215
if (error) { throw error; }
216216
done();
217217
});

test/functional/iDataQueueFunctional.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ describe('DataQueue Functional Tests', function () {
3030

3131
before('check if data queue exists for tests', function (done) {
3232
printConfig();
33-
checkObjectExists(config, dqName, '*DTAQ', (error) => {
33+
checkObjectExists(config, { name: dqName, type: '*DTAQ' }, (error) => {
3434
if (error) { throw error; }
3535

36-
checkObjectExists(config, dqName2, '*DTAQ', (error2) => {
36+
checkObjectExists(config, { name: dqName2, type: '*DTAQ' }, (error2) => {
3737
if (error2) { throw error2; }
3838
done();
3939
});

0 commit comments

Comments
 (0)