|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +var chai = require('chai'); |
| 4 | +chai.should(); |
| 5 | +var config = require('../../config'); |
| 6 | +var chaiAsPromised = require("chai-as-promised"); |
| 7 | +chai.use(chaiAsPromised); |
| 8 | +var queue = require('../../services/queue'); |
| 9 | + |
| 10 | +var workers = require('../../services/queue/workers'); |
| 11 | +var sinon = require("sinon"); |
| 12 | +var sinonChai = require("sinon-chai"); |
| 13 | +chai.use(sinonChai); |
| 14 | + |
| 15 | +// Test Index |
| 16 | +var jobs; |
| 17 | +describe('#Queue service', function(){ |
| 18 | + before(function() { /* jslint ignore:line */ |
| 19 | + queue.testMode.enter(); |
| 20 | + jobs = require('../../services/queue/jobs'); |
| 21 | + }); |
| 22 | + |
| 23 | + afterEach(function() { /* jslint ignore:line */ |
| 24 | + queue.testMode.clear(); |
| 25 | + }); |
| 26 | + |
| 27 | + after(function() { /* jslint ignore:line */ |
| 28 | + queue.testMode.exit(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should return an object', function(done){ |
| 32 | + queue.should.be.an('object'); |
| 33 | + queue.should.be.have.property('kue'); |
| 34 | + jobs.should.be.an('object'); |
| 35 | + workers.should.be.an('object'); |
| 36 | + done(); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should pass basic smoke test', function() { |
| 40 | + queue.createJob('myJob', 'foo').save(); |
| 41 | + queue.createJob('anotherJob', { baz: 'bip' }).save(); |
| 42 | + queue.testMode.jobs.length.should.equal(2); |
| 43 | + queue.testMode.jobs[0].type.should.equal('myJob'); |
| 44 | + queue.testMode.jobs[0].data.should.equal('foo'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should load processes', function() { |
| 48 | + var process = require('../../services/queue/workers'); |
| 49 | + // We have configured queue to create 2 workers per job making a total of 6 workers for 3 jobs that we currently have |
| 50 | + process.workers.length.should.equal(6); |
| 51 | + }); |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + // Test Jobs |
| 56 | + describe('#Testing Jobs', function(){ |
| 57 | + it('should run createRequestLog successfully', function(done){ |
| 58 | + var myrequestlog = { |
| 59 | + RequestId: 'gdfd6563', |
| 60 | + ipAddress: '192.168.90.9', |
| 61 | + url: 'http://google.com', |
| 62 | + method: 'POST', |
| 63 | + body: {name: 'femi'}, |
| 64 | + createdAt: new Date() |
| 65 | + }; |
| 66 | + jobs.createRequestLog(myrequestlog,done); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should run updateRequestLog successfully', function(done){ |
| 70 | + var myrequestlog = { |
| 71 | + requestId: 'gdfd6563', |
| 72 | + response: { |
| 73 | + ipAddress: '192.168.90.9', |
| 74 | + url: 'http://google.com', |
| 75 | + method: 'POST', |
| 76 | + body: {name: 'femi'}, |
| 77 | + createdAt: new Date() |
| 78 | + } |
| 79 | + }; |
| 80 | + jobs.updateRequestLog(myrequestlog,done); |
| 81 | + }); |
| 82 | + it('should run createSearchTags successfully for saving data', function(done){ |
| 83 | + var myrequestlog = { |
| 84 | + RequestId: 'gdfd6563', |
| 85 | + ipAddress: '192.168.90.9', |
| 86 | + url: 'http://google.com', |
| 87 | + method: 'POST', |
| 88 | + body: {name: 'femi'}, |
| 89 | + createdAt: new Date() |
| 90 | + }; |
| 91 | + |
| 92 | + myrequestlog.model = 'RequestLogs'; |
| 93 | + jobs.createSearchTags(myrequestlog,done); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should run createSearchTags successfully for updating data', function(done){ |
| 97 | + var myrequestlog = { |
| 98 | + RequestId: 'gdfd6563', |
| 99 | + ipAddress: '192.168.90.9', |
| 100 | + url: 'http://google.com', |
| 101 | + method: 'POST', |
| 102 | + body: {name: 'femi'}, |
| 103 | + createdAt: new Date() |
| 104 | + }; |
| 105 | + |
| 106 | + myrequestlog.model = 'RequestLogs'; |
| 107 | + myrequestlog.update = true; |
| 108 | + jobs.createSearchTags(myrequestlog,done); |
| 109 | + }); |
| 110 | + |
| 111 | + }); |
| 112 | +}); |
0 commit comments