UNPKG

docparse-dumpinvoices

Version:

takes a list of couchdb invoice ids and exports the data contained within those invoices to an Excel spreadsheet

93 lines (87 loc) 2.89 kB
var inspect = require('eyespect').inspector() var filed = require('filed') var temp = require('temp') var path = require('path') var fs = require('fs') var assert = require('assert') var should = require('should') var configFilePath = path.join(__dirname, 'config.json') assert.ok(fs.existsSync(configFilePath), 'config file not found at path: ' + configFilePath) var config = require('nconf').argv().env().file({file: configFilePath}) var db = require('cradle-nconf')(config) var dump = require('../index') var getFeed = require('../getFeed') var processStream = require('../processStream') describe('stream test', function() { this.timeout(0) this.slow(20*1000) it.only('should output a few invoices in database to spreadsheet', function(done) { inspect('starting stream test') var opts = { include_docs: true, key: 'NST', limit: 200 } db.view('invoice/bySupplierCode', opts, function (err, docs) { if (err) { inspect(err, 'error getting invoices') should.not.exist(err, 'error getting invoices: ' + JSON.stringify(err, null, ' ')) } if (docs.length === 0) { inspect('no docs found, test fails') } docs.length.should.be.above(0, 'no invoices found') var invoiceIDs = docs.map(function (doc) { return doc._id }) // invoiceIDs = invoiceIDs.splice(0,2000) // invoiceIDs = invoiceIDs.splice(0,10) var filePath = path.join(__dirname, 'data', 'test.xls') if (fs.existsSync(filePath)) { fs.unlinkSync(filePath) } var res = filed(filePath) var feedData = { config: config, db: db, invoiceIDs: invoiceIDs, res: res } dump(feedData, function (err, reply) { // var filePath = temp.path({suffix: '.xls'}) var count = 0 inspect('wrote to spreadsheet at path: ' + filePath) should.not.exist(err, 'error outputing invoices to spreadsheet: ' + err) done() }) }) }) it('should export all invoices to spreadsheet', function (done) { var filePath = path.join(__dirname, 'data', 'test.xls') if (fs.existsSync(filePath)) { fs.unlinkSync(filePath) } var opts = { include_docs: true } db.view('invoice/all', opts, function (err, docs) { docs.length.should.be.above(0, 'no invoices found') var invoiceIDs = docs.map(function (doc) { return doc._id }) var feedData = { config: config, db: db, invoiceIDs: invoiceIDs, res: filed(filePath) } dump(feedData, function (err, reply) { // var filePath = temp.path({suffix: '.xls'}) var count = 0 inspect('wrote to spreadsheet at path: ' + filePath) should.not.exist(err, 'error outputing invoices to spreadsheet: ' + err) done() }) }) }) })