add queue tests for job creation

This commit is contained in:
2016-07-12 13:22:40 -07:00
parent 775442f284
commit f8db6e1bd3
3 changed files with 83 additions and 1 deletions

View File

@@ -1,9 +1,17 @@
import events from 'events';
import expect from 'expect.js';
import sinon from 'sinon';
import proxyquire from 'proxyquire';
import { noop, times } from 'lodash';
import constants from '../../lib/constants';
import elasticsearchMock from '../fixtures/elasticsearch';
import Esqueue from '../../lib/index';
import jobMock from '../fixtures/job';
import workerMock from '../fixtures/worker';
const Esqueue = proxyquire.noPreserveCache()('../../lib/index', {
'./job.js': jobMock,
'./worker.js': workerMock,
});
describe('Esqueue class', function () {
let client;
@@ -48,6 +56,47 @@ describe('Esqueue class', function () {
});
});
describe('Adding jobs', function () {
let indexName;
let jobType;
let payload;
let queue;
beforeEach(function () {
indexName = 'esqueue-index';
jobType = 'test-test';
payload = { payload: true };
queue = new Esqueue(indexName, { client });
});
it('should pass queue instance, index name, type and payload', function () {
const job = queue.addJob(jobType, payload);
expect(job.getProp('queue')).to.equal(queue);
expect(job.getProp('index')).to.match(new RegExp(indexName));
expect(job.getProp('jobType')).to.equal(jobType);
expect(job.getProp('payload')).to.equal(payload);
});
it('should pass default settings', function () {
const job = queue.addJob(jobType, payload);
const options = job.getProp('options');
expect(options).to.have.property('timeout', constants.DEFAULT_SETTING_TIMEOUT);
expect(options).to.have.property('doctype', constants.DEFAULT_SETTING_DOCTYPE);
});
it('should pass queue index settings', function () {
const indexSettings = {
index: {
number_of_shards: 1
}
};
queue = new Esqueue(indexName, { client, indexSettings });
const job = queue.addJob(jobType, payload);
expect(job.getProp('options')).to.have.property('indexSettings', indexSettings);
});
});
describe('Registering workers', function () {
it('should keep track of workers', function () {
const queue = new Esqueue('esqueue', { client });