add tests for the output formatting

This commit is contained in:
2016-05-03 09:58:39 -07:00
parent 14ea4617e2
commit 552abb7ddd

View File

@@ -11,6 +11,8 @@ const defaults = {
timeout: 10000, timeout: 10000,
interval: 1500, interval: 1500,
size: 10, size: 10,
unknownMime: false,
contentBody: null,
}; };
describe('Worker class', function () { describe('Worker class', function () {
@@ -56,16 +58,59 @@ describe('Worker class', function () {
describe('construction', function () { describe('construction', function () {
it('should have a unique ID', function () { it('should have a unique ID', function () {
var worker = new Worker(mockQueue, 'test', noop); const worker = new Worker(mockQueue, 'test', noop);
expect(worker.id).to.be.a('string'); expect(worker.id).to.be.a('string');
var worker2 = new Worker(mockQueue, 'test', noop); const worker2 = new Worker(mockQueue, 'test', noop);
expect(worker2.id).to.be.a('string'); expect(worker2.id).to.be.a('string');
expect(worker.id).to.not.equal(worker2.id); expect(worker.id).to.not.equal(worker2.id);
}); });
}); });
describe('output formatting', function () {
let worker;
let f;
beforeEach(function () {
worker = new Worker(mockQueue, 'test', noop);
f = (output) => worker._formatOutput(output);
});
it('should handle primitives', function () {
const primitives = ['test', true, 1234, { one: 1}, [5, 6, 7, 8]];
primitives.forEach((val) => {
expect(f(val)).to.have.property('content_type', defaults.unknownMime);
expect(f(val)).to.have.property('content', val);
});
});
it('should accept content object without type', function () {
const output = {
content: 'test output'
};
expect(f(output)).to.have.property('content_type', defaults.unknownMime);
expect(f(output)).to.have.property('content', output.content);
});
it('should accept a content type', function () {
const output = {
content_type: 'test type',
content: 'test output'
};
expect(f(output)).to.have.property('content_type', output.content_type);
expect(f(output)).to.have.property('content', output.content);
});
it('should work with no input', function () {
expect(f()).to.have.property('content_type', defaults.unknownMime);
expect(f()).to.have.property('content', defaults.contentBody);
});
});
describe('searching for jobs', function () { describe('searching for jobs', function () {
it('should start polling for jobs after interval', function () { it('should start polling for jobs after interval', function () {
const searchSpy = sinon.spy(mockQueue.client, 'search'); const searchSpy = sinon.spy(mockQueue.client, 'search');
@@ -347,4 +392,11 @@ describe('Worker class', function () {
}); });
}); });
// describe('job timeouts', function () {
// let job;
// let payload;
// let updateSpy;
// });
}); });