UNPKG

datapumps

Version:

Node.js ETL (Extract, Transform, Load) toolkit for easy data import, export or transfer between systems.

82 lines (75 loc) 2.26 kB
(function() { var ExcelReaderMixin, sinon, xlsx; require('should'); sinon = require('sinon'); ExcelReaderMixin = require('../ExcelReaderMixin'); xlsx = require('xlsx'); describe('ExcelReaderMixin(options)', function() { it('should require worksheet property', function() { return (function() { var mixin, target; mixin = ExcelReaderMixin({}); target = {}; return mixin(target); }).should["throw"]('worksheet property is required for ExcelReaderMixin'); }); it('should read workbook if path is given', function() { var mixin, target; target = { from: sinon.spy() }; mixin = ExcelReaderMixin({ path: __dirname + '/data/nameAndAddress.xlsx', worksheet: 'TestSheet' }); mixin(target); target.from.calledOnce.should.be["true"]; return target.from.getCall(0).args[0].getContent().should.eql([ { Name: 'foo', Address: 'bar' } ]); }); it('should convert worksheet into json and put it in the input buffer of the pump', function() { var mixin, target, workbook; workbook = xlsx.readFile(__dirname + '/data/nameAndAddress.xlsx'); target = { from: sinon.spy() }; mixin = ExcelReaderMixin({ worksheet: workbook.Sheets.TestSheet }); mixin(target); target.from.calledOnce.should.be["true"]; return target.from.getCall(0).args[0].getContent().should.eql([ { Name: 'foo', Address: 'bar' } ]); }); return it('should use columnMapping to convert fill the input buffer', function() { var mixin, target, workbook; workbook = xlsx.readFile(__dirname + '/data/nameAndAddress.xlsx'); target = { from: sinon.spy() }; mixin = ExcelReaderMixin({ worksheet: workbook.Sheets.TestSheet, columnMapping: { Name: 'name', Address: 'address' } }); mixin(target); target.from.calledOnce.should.be["true"]; return target.from.getCall(0).args[0].getContent().should.eql([ { name: 'foo', address: 'bar' } ]); }); }); }).call(this);