From 0eaab95f4b92d1fd0d85533749fa59e9fefc1ab3 Mon Sep 17 00:00:00 2001 From: Ian Goldstein Date: Tue, 15 Aug 2017 12:30:50 -0700 Subject: [PATCH] tweaks to tests/clock, tests/config, tests/jobQueue (#521) --- tests/clock/kueStatsActivityLogs.js | 19 ++-- tests/config/configUtil.js | 118 +++++++++-------------- tests/jobQueue/v1/bulkUpsert.js | 16 +-- tests/jobQueue/v1/getBulkUpsertStatus.js | 34 ++++--- tests/jobQueue/v1/getHierarchy.js | 47 +++------ 5 files changed, 89 insertions(+), 145 deletions(-) diff --git a/tests/clock/kueStatsActivityLogs.js b/tests/clock/kueStatsActivityLogs.js index 7daef6e50a..adb1bc906e 100644 --- a/tests/clock/kueStatsActivityLogs.js +++ b/tests/clock/kueStatsActivityLogs.js @@ -18,17 +18,16 @@ const TWO = 2; const client = redis.client.realtimeLogging; describe('kueStatsActivityLogs', () => { - it('generateLogObject', (done) => { + it('generateLogObject', () => { k.generateLogObject() .then((obj) => { - expect(obj).to.be.an('object'); - expect(obj).to.have.property('activity', 'kueStats'); - expect(obj).to.have.property('activeCount'); - expect(obj).to.have.property('completeCount'); - expect(obj).to.have.property('failedCount'); - expect(obj).to.have.property('inactiveCount'); - expect(obj).to.have.property('workTimeMillis'); - done(); - }) + expect(obj).to.be.an('object'); + expect(obj).to.have.property('activity', 'kueStats'); + expect(obj).to.have.property('activeCount'); + expect(obj).to.have.property('completeCount'); + expect(obj).to.have.property('failedCount'); + expect(obj).to.have.property('inactiveCount'); + expect(obj).to.have.property('workTimeMillis'); + }); }); }); diff --git a/tests/config/configUtil.js b/tests/config/configUtil.js index b2c6e1bb61..6e985787d5 100644 --- a/tests/config/configUtil.js +++ b/tests/config/configUtil.js @@ -10,55 +10,51 @@ * tests/config/configUtil.js * * Tests config utilities -*/ - + */ +'use strict'; const expect = require('chai').expect; const configUtil = require('../../config/configUtil'); - const NOT_ALLOWED = 'Your IP address is not allowed. Verify your ' + 'network address and your Refocus IP settings'; describe('IP List', () => { - it('parse default IP list', (done) => { + it('parse default IP list', () => { const iplist = configUtil.parseIPlist('[[0.0.0.0,255.255.255.255]]'); expect(iplist).to.have.length(1); expect(iplist).to.be.eql([['0.0.0.0', '255.255.255.255']]); - done(); }); - it('parse IP list with space around opening bracket', (done) => { - const iplist = configUtil.parseIPlist('[ [1.2.3.4,1.2.3.8],[7.6.5.4,7.6.9.9]]'); + it('parse IP list with space around opening bracket', () => { + const iplist = + configUtil.parseIPlist('[ [1.2.3.4,1.2.3.8],[7.6.5.4,7.6.9.9]]'); expect(iplist).to.have.length(2); expect(iplist).to.be.eql([ ['1.2.3.4', '1.2.3.8'], ['7.6.5.4', '7.6.9.9'], ]); - done(); }); - it('parse IP list with space around closing bracket', (done) => { - const iplist = configUtil - .parseIPlist('[[1.2.3.4,1.2.3.8],[7.6.5.4,7.6.9.9 ] ]'); + it('parse IP list with space around closing bracket', () => { + const iplist = + configUtil.parseIPlist('[[1.2.3.4,1.2.3.8],[7.6.5.4,7.6.9.9 ] ]'); expect(iplist).to.have.length(2); expect(iplist).to.be.eql([ ['1.2.3.4', '1.2.3.8'], ['7.6.5.4', '7.6.9.9'], ]); - done(); }); - it('parse IP list with space around comma', (done) => { - const iplist = configUtil - .parseIPlist('[[1.2.3.4, 1.2.3.8], [7.6.5.4,7.6.9.9]]'); + it('parse IP list with space around comma', () => { + const iplist = + configUtil.parseIPlist('[[1.2.3.4, 1.2.3.8], [7.6.5.4,7.6.9.9]]'); expect(iplist).to.have.length(2); expect(iplist).to.be.eql([ ['1.2.3.4', '1.2.3.8'], ['7.6.5.4', '7.6.9.9'], ]); - done(); }); - it('parse IP list with misc spaces', (done) => { + it('parse IP list with misc spaces', () => { const iplist = configUtil .parseIPlist('[ [ 1.2.3.4, 1.2.3.8], [7.6.5.4, 7.6.9.9 ] ]'); expect(iplist).to.have.length(2); @@ -66,108 +62,80 @@ describe('IP List', () => { ['1.2.3.4', '1.2.3.8'], ['7.6.5.4', '7.6.9.9'], ]); - done(); }); - it('error parsing IP list with wrong format', (done) => { + it('error parsing IP list with wrong format', () => { expect(configUtil.parseIPlist.bind( configUtil.parseIPlist, '[ [ 1.2.3.4, 1.2.3.8], [7.6.5.4] ]') ) .to.throw(NOT_ALLOWED); - done(); }); }); describe('csvToArray', () => { - it('undefined string', (done) => { - expect(configUtil.csvToArray(undefined)) - .to.be.eql([]); - done(); + it('undefined string', () => { + expect(configUtil.csvToArray(undefined)).to.be.eql([]); }); - it('null string', (done) => { - expect(configUtil.csvToArray(null)) - .to.be.eql([]); - done(); + it('null string', () => { + expect(configUtil.csvToArray(null)).to.be.eql([]); }); - it('zero-length string', (done) => { - expect(configUtil.csvToArray('')) - .to.be.eql([]); - done(); + it('zero-length string', () => { + expect(configUtil.csvToArray('')).to.be.eql([]); }); - it('single element', (done) => { - expect(configUtil.csvToArray('abc')) - .to.be.eql(['abc']); - done(); + it('single element', () => { + expect(configUtil.csvToArray('abc')).to.be.eql(['abc']); }); - it('multiple elements with extra left and right padding', (done) => { + it('multiple elements with extra left and right padding', () => { expect(configUtil.csvToArray('abc,def , ghi')) .to.be.eql(['abc', 'def', 'ghi']); - done(); }); }); // csvToArray describe('csvToArray', () => { - it('undefined string', (done) => { - expect(configUtil.csvToArray(undefined)) - .to.be.eql([]); - done(); + it('undefined string', () => { + expect(configUtil.csvToArray(undefined)).to.be.eql([]); }); - it('null string', (done) => { - expect(configUtil.csvToArray(null)) - .to.be.eql([]); - done(); + it('null string', () => { + expect(configUtil.csvToArray(null)).to.be.eql([]); }); - it('zero-length string', (done) => { - expect(configUtil.csvToArray('')) - .to.be.eql([]); - done(); + it('zero-length string', () => { + expect(configUtil.csvToArray('')).to.be.eql([]); }); - it('single element', (done) => { - expect(configUtil.csvToArray('abc')) - .to.be.eql(['abc']); - done(); + it('single element', () => { + expect(configUtil.csvToArray('abc')).to.be.eql(['abc']); }); - it('multiple elements with extra left and right padding', (done) => { + it('multiple elements with extra left and right padding', () => { expect(configUtil.csvToArray('abc,def , ghi')) .to.be.eql(['abc', 'def', 'ghi']); - done(); }); }); // csvToArray describe('getReadReplicas', () => { - it('only bad entry will return undefined', (done) => { - const pe = { 'REPLICAS': 'test' }; - expect(configUtil.getReadReplicas(pe, 'REPLICAS')) - .to.be.eql(undefined); - done(); + it('only bad entry will return undefined', () => { + const pe = { REPLICAS: 'test' }; + expect(configUtil.getReadReplicas(pe, 'REPLICAS')).to.be.eql(undefined); }); - it('without Replicas env variable return undefined', (done) => { + it('without Replicas env variable return undefined', () => { const pe = {}; - expect(configUtil.getReadReplicas(pe, 'REPLICAS')) - .to.be.eql(undefined); - done(); + expect(configUtil.getReadReplicas(pe, 'REPLICAS')).to.be.eql(undefined); }); - it('Replicas env variable with correct env variables', (done) => { - const pe = { 'REPLICAS': 'test', 'test': 'testURL' }; - expect(configUtil.getReadReplicas(pe, 'REPLICAS')) - .to.be.eql(['testURL']); - done(); + it('Replicas env variable with correct env variables', () => { + const pe = { REPLICAS: 'test', test: 'testURL' }; + expect(configUtil.getReadReplicas(pe, 'REPLICAS')).to.be.eql(['testURL']); }); - it('Replicas env variable with bad env variables', (done) => { - const pe = { 'REPLICAS': 'test, test1', 'test': 'testURL' }; - expect(configUtil.getReadReplicas(pe, 'REPLICAS')) - .to.be.eql(['testURL']); - done(); + it('Replicas env variable with bad env variables', () => { + const pe = { REPLICAS: 'test, test1', test: 'testURL' }; + expect(configUtil.getReadReplicas(pe, 'REPLICAS')).to.be.eql(['testURL']); }); }); diff --git a/tests/jobQueue/v1/bulkUpsert.js b/tests/jobQueue/v1/bulkUpsert.js index d6613528c7..7669bfd158 100644 --- a/tests/jobQueue/v1/bulkUpsert.js +++ b/tests/jobQueue/v1/bulkUpsert.js @@ -10,7 +10,6 @@ * tests/jobQueue/v1/bulkUpsert.js */ 'use strict'; // eslint-disable-line strict - const jobQueue = require('../../../jobQueue/setup').jobQueue; const jobType = require('../../../jobQueue/setup').jobType; const bulkUpsertSamplesJob = require('../../../worker/jobs/bulkUpsertSamplesJob'); @@ -84,16 +83,10 @@ describe('api: POST using worker process ' + path, () => { .expect(constants.httpStatus.OK) .expect((res) => { expect(res.body.status).to.contain('OK'); - // make sure that the jobId is returned as a part of the response. + /* make sure that the jobId is returned as a part of the response. */ expect(res.body.jobId).to.be.at.least(1); }) - .end((err) => { - if (err) { - done(err); - } - - done(); - }); + .end(done); }); it('test logging', (done) => { @@ -119,7 +112,7 @@ describe('api: POST using worker process ' + path, () => { .expect(constants.httpStatus.OK) .end((err, res) => { if (err) { - done(err); + return done(err); } //don't call done() yet, need to wait for data to be logged @@ -189,7 +182,6 @@ describe('api: POST using worker process ' + path, () => { done(err); } } - }; }); @@ -215,7 +207,7 @@ describe('api: POST using worker process ' + path, () => { }, ]) .expect(constants.httpStatus.BAD_REQUEST) - .end((err) => err ? done(err) : done()); + .end(done); }); }); }); diff --git a/tests/jobQueue/v1/getBulkUpsertStatus.js b/tests/jobQueue/v1/getBulkUpsertStatus.js index bb718e11a6..7bf472ca30 100644 --- a/tests/jobQueue/v1/getBulkUpsertStatus.js +++ b/tests/jobQueue/v1/getBulkUpsertStatus.js @@ -10,7 +10,6 @@ * tests/jobQueue/v1/getBulkUpsertStatus.js */ 'use strict'; // eslint-disable-line strict - const jobSetup = require('../../../jobQueue/setup'); const jobQueue = jobSetup.jobQueue; const expect = require('chai').expect; @@ -81,12 +80,12 @@ describe('api: GET ' + getStatusPath, () => { { name: `${tu.namePrefix}Subject|${tu.namePrefix}Aspect2`, value: '10', - } + }, ]) .expect(constants.httpStatus.OK) .expect((res) => { expect(res.body.status).to.contain('OK'); - // make sure that the jobId is returned as a part of the response. + /* make sure that the jobId is returned as a part of the response. */ expect(res.body.jobId).to.be.at.least(1); jobId = res.body.jobId; }) @@ -103,11 +102,12 @@ describe('api: GET ' + getStatusPath, () => { api.get(getStatusPath.replace('{jobId}', jobId)) .end((err, res) => { if (err) { - done(err); + return done(err); } + expect(res.body.status).to.equal('complete'); expect(res.body.errors.length).to.equal(0); - return done(); + done(); }); }, 500); }); @@ -129,18 +129,17 @@ describe('api: GET ' + getStatusPath, () => { { name: `${tu.namePrefix}Subject|${tu.namePrefix}Aspect2`, value: '10', - status: 'Info' + status: 'Info', }, { name: `${tu.namePrefix}Subject|${tu.namePrefix}_InvalidAspect`, value: '10', - } - + }, ]) .expect(constants.httpStatus.OK) .expect((res) => { expect(res.body.status).to.contain('OK'); - // make sure that the jobId is returned as a part of the response. + /* make sure that the jobId is returned as a part of the response. */ expect(res.body.jobId).to.be.at.least(1); jobId = res.body.jobId; }) @@ -157,8 +156,9 @@ describe('api: GET ' + getStatusPath, () => { api.get(getStatusPath.replace('{jobId}', jobId)) .end((err, res) => { if (err) { - done(err); + return done(err); } + expect(res.body.status).to.equal('complete'); expect(res.body.errors.length).to.equal(2); expect(res.body.errors[0].name).to.equal('ValidationError'); @@ -176,7 +176,7 @@ describe('api: GET ' + getStatusPath, () => { const toUpsert = []; // read-only field validation error - for (let i = 0;i< 50;i++) { + for (let i = 0; i < 50; i++) { toUpsert.push({ name: `${tu.namePrefix}Subject|${tu.namePrefix}Aspect1`, value: '10', @@ -185,7 +185,7 @@ describe('api: GET ' + getStatusPath, () => { } // aspect not found - for (let i = 0;i< 25;i++) { + for (let i = 0; i < 25; i++) { toUpsert.push({ name: `${tu.namePrefix}Subject|${tu.namePrefix}Aspect_Invalid`, value: '10', @@ -193,7 +193,7 @@ describe('api: GET ' + getStatusPath, () => { } // subject not found - for (let i = 0;i< 25;i++) { + for (let i = 0; i < 25; i++) { toUpsert.push({ name: `${tu.namePrefix}Subject_Invalid|${tu.namePrefix}Aspect1`, value: '10', @@ -211,7 +211,7 @@ describe('api: GET ' + getStatusPath, () => { .expect(constants.httpStatus.OK) .expect((res) => { expect(res.body.status).to.contain('OK'); - // make sure that the jobId is returned as a part of the response. + /* make sure that the jobId is returned as a part of the response. */ expect(res.body.jobId).to.be.at.least(1); jobId = res.body.jobId; }) @@ -228,8 +228,9 @@ describe('api: GET ' + getStatusPath, () => { api.get(getStatusPath.replace('{jobId}', jobId)) .end((err, res) => { if (err) { - done(err); + return done(err); } + expect(res.body.status).to.equal('complete'); expect(res.body.errors.length).to.equal(100); return done(); @@ -249,8 +250,9 @@ describe('api: GET ' + getStatusPath, () => { .expect(constants.httpStatus.NOT_FOUND) .end((err, res) => { if (err) { - done(err); + return done(err); } + expect(res.body.errors[0].type).to.contain('ResourceNotFoundError'); done(); }); diff --git a/tests/jobQueue/v1/getHierarchy.js b/tests/jobQueue/v1/getHierarchy.js index ea42ea2802..5af18f3d14 100644 --- a/tests/jobQueue/v1/getHierarchy.js +++ b/tests/jobQueue/v1/getHierarchy.js @@ -24,25 +24,16 @@ const path = '/v1/subjects/{key}/hierarchy'; const logger = require('../../../utils/activityLog').logger; describe(`api: GET using worker process ${path}`, () => { - before(() => { tu.toggleOverride('enableWorkerProcess', true); tu.toggleOverride('enqueueHierarchy', true); jobQueue.process(jobType.GET_HIERARCHY, getHierarchyJob); - }); - - before(() => { jobQueue.testMode.enter(true); jobQueue.testMode.clear(); }); - afterEach(() => { - jobQueue.testMode.clear(); - }); - - after(() => { - jobQueue.testMode.exit() - }); + afterEach(() => jobQueue.testMode.clear()); + after(() => jobQueue.testMode.exit()); //run normal getHierarchy tests with worker enabled require('../../api/v1/subjects/getHierarchy'); @@ -50,28 +41,22 @@ describe(`api: GET using worker process ${path}`, () => { require('../../api/v1/subjects/getHierarchyStatusAndCombinedFilters'); describe(`api: GET using worker process ${path}`, () => { - let token; - const par = { name: `${tu.namePrefix}NorthAmerica`, isPublished: true }; const chi = { name: `${tu.namePrefix}Canada`, isPublished: true }; const grn = { name: `${tu.namePrefix}Quebec`, isPublished: true }; - const aspect = { name: 'temperature', timeout: '30s', isPublished: true, rank: 10, }; - const sample1 = { value: '10' }; - + const invalidKey = '00000'; + const invalidFilterParams = '?status=aaa,-aaa'; + let token; let ipar = 0; let ichi = 0; let igrn = 0; - - const invalidKey = '00000'; - const invalidFilterParams = '?status=aaa,-aaa'; - let nonWorkerResponse; // setup hierarchy @@ -112,7 +97,7 @@ describe(`api: GET using worker process ${path}`, () => { token = returnedToken; done(); }) - .catch((err) => done(err)); + .catch(done); }); //get non-worker response @@ -123,7 +108,7 @@ describe(`api: GET using worker process ${path}`, () => { .set('Authorization', token) .end((err, res) => { if (err) { - done(err); + return done(err); } nonWorkerResponse = res.body; @@ -140,7 +125,7 @@ describe(`api: GET using worker process ${path}`, () => { .expect(constants.httpStatus.OK) .end((err) => { if (err) { - done(err); + return done(err); } expect(jobQueue.testMode.jobs.length).to.equal(n); @@ -178,7 +163,7 @@ describe(`api: GET using worker process ${path}`, () => { .expect(constants.httpStatus.OK) .end((err) => { if (err) { - done(err); + return done(err); } // make sure the job is enqueued @@ -200,7 +185,7 @@ describe(`api: GET using worker process ${path}`, () => { .expect(constants.httpStatus.OK) .end((err, res) => { if (err) { - done(err); + return done(err); } expect(res.body).to.deep.equal(nonWorkerResponse); @@ -223,12 +208,11 @@ describe(`api: GET using worker process ${path}`, () => { tu.toggleOverride('enableWorkerActivityLogs', false); if (err) { - done(err); + return done(err); } expect(workerLogged).to.be.true; expect(apiLogged).to.be.true; - done(); }); @@ -284,7 +268,6 @@ describe(`api: GET using worker process ${path}`, () => { done(err); } } - }; }); @@ -294,13 +277,14 @@ describe(`api: GET using worker process ${path}`, () => { .expect(constants.httpStatus.NOT_FOUND) .end((err, res) => { if (err) { - done(err); + return done(err); } expect(res.body.errors).to.exist; expect(res.body.errors[0]).to.exist; err = res.body.errors[0]; - expect(err.message).to.equal('An unexpected ResourceNotFoundError occurred.'); + expect(err.message) + .to.equal('An unexpected ResourceNotFoundError occurred.'); expect(err.source).to.equal('Subject'); expect(err.value).to.equal(invalidKey); expect(err.type).to.equal('ResourceNotFoundError'); @@ -315,7 +299,7 @@ describe(`api: GET using worker process ${path}`, () => { .expect(constants.httpStatus.BAD_REQUEST) .end((err, res) => { if (err) { - done(err); + return done(err); } expect(res.body.errors).to.exist; @@ -338,5 +322,4 @@ describe(`api: GET using worker process ${path}`, () => { tu.toggleOverride('enableWorkerProcess', false); tu.toggleOverride('enqueueHierarchy', false); }); - });