datapumps
Version:
Node.js ETL (Extract, Transform, Load) toolkit for easy data import, export or transfer between systems.
98 lines (92 loc) • 3.11 kB
JavaScript
(function() {
var ExcelWriterMixin, sinon;
require('should');
sinon = require('sinon');
ExcelWriterMixin = require('../ExcelWriterMixin');
describe('ExcelWriterMixin(onMixin)', function() {
it('should call function in onMixin argument on mixin in target context', function(done) {
var mixin, target;
target = {
on: function() {}
};
mixin = ExcelWriterMixin(function() {
target.should.equal(this);
return done();
});
return mixin(target);
});
it('should write excel file on end of pumping if workbook was opened', function() {
var mixin, target;
target = {
eventHandler: {},
on: function(event, cb) {
return target.eventHandler[event] = cb;
}
};
mixin = ExcelWriterMixin(function() {
return target.createWorkbook('test.xlsx');
});
mixin(target);
target._excel.workbook.write = sinon.spy();
target.eventHandler.end();
return target._excel.workbook.write.calledOnce.should.be["true"];
});
it('should not be possible to write headers before creating a worksheet', function() {
var mixin, target;
target = {
on: function() {}
};
mixin = ExcelWriterMixin(function() {});
mixin(target);
return (function() {
return target.writeHeaders(['test ']);
}).should["throw"]('Use createWorksheet before writing headers');
});
it('should not be possible to write headers if rows were already written to the worksheet', function() {
var mixin, target;
target = {
on: function() {}
};
mixin = ExcelWriterMixin(function() {
target.createWorkbook('test.xlsx');
return target.createWorksheet('Customers');
});
mixin(target);
return (function() {
target.writeRow(['test ']);
return target.writeHeaders(['test ']);
}).should["throw"]('Use writeHeaders before writing any rows to the worksheet');
});
it('should not be possible to write rows before creating a worksheet', function() {
var mixin, target;
target = {
on: function() {}
};
mixin = ExcelWriterMixin(function() {});
mixin(target);
return (function() {
return target.writeRow(['test ']);
}).should["throw"]('Use createWorksheet before writing rows');
});
return it('should leave cells with null or undefined value empty', function() {
var cell, mixin, target;
target = {
on: function() {}
};
mixin = ExcelWriterMixin(function() {
target.createWorkbook('test.xlsx');
return target.createWorksheet('Customer');
});
mixin(target);
target._excel.workbook.write = function() {};
cell = {
String: sinon.spy()
};
target._excel.worksheet.Cell = sinon.stub().returns(cell);
target.writeRow([null]);
cell.String.calledOnce.should.be["false"];
target.writeRow(['test']);
return cell.String.calledOnce.should.be["true"];
});
});
}).call(this);