datapumps
Version:
Node.js ETL (Extract, Transform, Load) toolkit for easy data import, export or transfer between systems.
65 lines (58 loc) • 2.27 kB
JavaScript
(function() {
var BatchMixin, Pump, sinon;
require('should');
sinon = require('sinon');
BatchMixin = require('../BatchMixin');
Pump = require('../../Pump');
describe('BatchMixin', function() {
it('should call processBatch to process items', function(done) {
var processCallback, pump;
processCallback = sinon.spy();
return (pump = new Pump).mixin(BatchMixin).from(pump.createBuffer({
size: 10,
content: ['foo', 'bar', 'yeehaa'],
sealed: true
})).batchSize(2).processBatch(processCallback).start().whenFinished().then((function(_this) {
return function() {
processCallback.calledTwice.should.be["true"];
processCallback.getCall(0).args[0].should.eql(['foo', 'bar']);
processCallback.getCall(1).args[0].should.eql(['yeehaa']);
return done();
};
})(this));
});
it('should process input buffers with item count less than batch size', function(done) {
var processCallback, pump;
processCallback = sinon.spy();
return (pump = new Pump).mixin(BatchMixin).from(pump.createBuffer({
size: 10,
content: ['foo', 'bar', 'yeehaa'],
sealed: true
})).processBatch(processCallback).start().whenFinished().then((function(_this) {
return function() {
processCallback.calledOnce.should.be["true"];
processCallback.getCall(0).args[0].should.eql(['foo', 'bar', 'yeehaa']);
return done();
};
})(this));
});
it('should not call .processBatch for empty inputs', function(done) {
var processCallback, pump;
processCallback = sinon.spy();
return (pump = new Pump).mixin(BatchMixin).from(pump.createBuffer({
sealed: true
})).processBatch(processCallback).start().whenFinished().then((function(_this) {
return function() {
processCallback.called.should.be["false"];
return done();
};
})(this));
});
return it('should not allow setting batch size to zero or less', function() {
return (function() {
var pump;
return (pump = new Pump).mixin(BatchMixin).batchSize(0);
}).should["throw"]('Invalid batch size: 0');
});
});
}).call(this);