docparse-supplier-nge
Version:
process ngrid electric utility bill data for use in the docparse system
135 lines (114 loc) • 5.3 kB
JavaScript
var fs = require('fs');
var should = require('should');
var assert = require('assert');
var path = require('path');
var inspect = require('eyespect').inspector({maxLength: 2000000});
var scraperProcessData = require('../scraperProcessData');
var getData = require('../lib/parse/getData');
var Invoice = require('docparse-invoice');
var createSupplier = require('docparse-create-supplier');
var createCustomer = require('docparse-create-customer');
var nge = require('../index');
var mongoose = require('mongoose');
function connect(cb) {
mongoose.disconnect(function () {
mongoose.connect('mongodb://localhost/test');
cb();
});
}
describe('NGrid Electric Cost Delivery', function() {
var pdfText;
var scraperData;
before(function(done) {
connect(function () {
createCustomer(function (err, customer) {
should.not.exist(err, 'error creating NGrid Electric customer document in database: ' + err);
var filePath = path.join(__dirname, 'data/compSupplyBillText.json');
assert.ok(fs.existsSync(filePath, 'default bill text json file not found at path: ' + filePath));
fs.readFile(filePath,'utf8', function (err, text) {
should.not.exist(err)
scraperData = JSON.parse(text);
should.exist(scraperData);
scraperData.should.have.property('text_pages');
should.exist(scraperData);
scraperData.should.have.property('text_pages')
scraperData.should.have.property('hash');
scraperData.should.have.property('bill_number');
scraperData.should.have.property('bill_date');
scraperData.should.have.property('from_date');
scraperData.should.have.property('to_date');
scraperData.should.have.property('supplier_code');
scraperData.should.have.property('account_number');
// scraperData.bill_number.should.eql('99da2eebb4a0aba283660cc172d7c8cd');
// scraperData.account_number.should.eql('0340465054');
// scraperData.bill_date.should.eql('2011 01 25');
// scraperData.from_date.should.eql('2011 01 14');
// scraperData.to_date.should.eql('2011 01 21');
// scraperData.supplier_code.should.eql('NGE');
scraperData.login_id = customer._id.toString();
// scraperData.hash.should.eql('569d7656f17895da8ab6ec2a275b71ea826a1d8c', 'wrong hash for bill');
// scraperData.text_pages.length.should.eql(3, 'wrong number of text_pages in default bill text json file at path: ' + filePath);
// pdfText = scraperData.text_pages.join('');
done();
});
});
});
});
it('should get correct values for all utility data fields', function(done) {
getData(pdfText, function (err, reply) {
should.not.exist(err,'error getting utility data: ' + err);
should.exist(reply,'no utility data returned when it should have been');
// check use
reply.should.have.property('use');
var use = reply.use;
use.should.have.property('quantity')
use.should.have.property('units')
use.units.should.eql('kwh');
// check cost_delivery
reply.should.have.property('cost_delivery');
// reply.cost_delivery.should.eql('700.22');
// // check cost_other
// reply.should.have.property('cost_other');
// var costOther = reply.cost_other;
// costOther.should.have.property('costs');
// costOther.costs.length.should.eql(1);
// var cost = costOther.costs[0];
// cost.should.have.property('description');
// cost.description.should.eql('Sales Tax 6.25 %');
// cost.should.have.property('value');
// cost.value.should.eql('135.91');
// costOther.should.have.property('total');
// costOther.total.should.eql('135.91');
// reply.should.have.property('cost_supply');
// reply.cost_supply.should.eql('1619.56');
done()
});
});
it.only('scraperProcessData function should complete correctly', function(done) {
var supplierData = {
supplierName: 'NGrid Electric',
supplierCode: 'NGE'
}
createSupplier(supplierData, function(err, supplier) {
should.not.exist(err, 'error creating ngrid electric supplier: ' + err);
should.exist(supplier, 'failed to create ngrid electric supplier');
scraperData.supplier = supplier;
// create the upload;
should.not.exist(err, 'error creating test upload document: ' + err);
nge.should.have.property('scraperProcessData');
nge.scraperProcessData(scraperData, function (err, bill) {
should.not.exist(err, 'error parsing upload: ' + err);
should.exist(bill, 'no bill returned from parseUpload');
bill.text_pages = ['truncated', 'here'];
// bill.invoices.length.should.eql(1,'there should be exactly 1 invoice attatched to this bill');
// Invoice.findById(bill.invoices[0], function (err, reply) {
// should.not.exist(err, 'error looking up invoice: ' + err);
// should.exist(reply, 'we should be able to find the invoice linked to the bill');
// inspect(reply.toObject(),'invoice 1');
// done();
// });
});
});
});
after(function(done) { mongoose.disconnect(done); });
});