From 552abb7ddd5c9a6e6a7b68f013dcaa6c4b0cdc72 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Tue, 3 May 2016 09:58:39 -0700 Subject: [PATCH] add tests for the output formatting --- test/src/worker.js | 56 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/test/src/worker.js b/test/src/worker.js index 200841b..148e46b 100644 --- a/test/src/worker.js +++ b/test/src/worker.js @@ -11,6 +11,8 @@ const defaults = { timeout: 10000, interval: 1500, size: 10, + unknownMime: false, + contentBody: null, }; describe('Worker class', function () { @@ -56,16 +58,59 @@ describe('Worker class', function () { describe('construction', 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'); - var worker2 = new Worker(mockQueue, 'test', noop); + const worker2 = new Worker(mockQueue, 'test', noop); expect(worker2.id).to.be.a('string'); 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 () { it('should start polling for jobs after interval', function () { 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; + +// }); + });