add queue tests for job creation
This commit is contained in:
17
test/fixtures/job.js
vendored
Normal file
17
test/fixtures/job.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import events from 'events';
|
||||||
|
|
||||||
|
export default class Job extends events.EventEmitter {
|
||||||
|
constructor(queue, index, type, payload, options = {}) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.queue = queue;
|
||||||
|
this.index = index;
|
||||||
|
this.jobType = type;
|
||||||
|
this.payload = payload;
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
getProp(name) {
|
||||||
|
return this[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
16
test/fixtures/worker.js
vendored
Normal file
16
test/fixtures/worker.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import events from 'events';
|
||||||
|
|
||||||
|
export default class Worker extends events.EventEmitter {
|
||||||
|
constructor(queue, type, workerFn, opts = {}) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.queue = queue;
|
||||||
|
this.type = type;
|
||||||
|
this.workerFn = workerFn;
|
||||||
|
this.options = opts;
|
||||||
|
}
|
||||||
|
|
||||||
|
getProp(name) {
|
||||||
|
return this[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,17 @@
|
|||||||
import events from 'events';
|
import events from 'events';
|
||||||
import expect from 'expect.js';
|
import expect from 'expect.js';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
import proxyquire from 'proxyquire';
|
||||||
import { noop, times } from 'lodash';
|
import { noop, times } from 'lodash';
|
||||||
|
import constants from '../../lib/constants';
|
||||||
import elasticsearchMock from '../fixtures/elasticsearch';
|
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 () {
|
describe('Esqueue class', function () {
|
||||||
let client;
|
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 () {
|
describe('Registering workers', function () {
|
||||||
it('should keep track of workers', function () {
|
it('should keep track of workers', function () {
|
||||||
const queue = new Esqueue('esqueue', { client });
|
const queue = new Esqueue('esqueue', { client });
|
||||||
|
|||||||
Reference in New Issue
Block a user