UNPKG

docparse-supplier-nge

Version:

process ngrid electric utility bill data for use in the docparse system

42 lines (37 loc) 1.59 kB
var fs = require('fs'); var should = require('should'); var assert = require('assert'); var path = require('path'); var inspect = require('eyespect').inspector(); var getSupplyText = require('../lib/parse/getSupplyText'); describe('Get Supply Text', function() { it('should return null when no supply text is found', function(done) { var filePath = path.join(__dirname, 'data/deliveryOnly.json'); assert.ok(fs.existsSync(filePath, 'bill text json file not found at path: ' + filePath)); fs.readFile(filePath,'utf8', function (err, text) { should.not.exist(err); var data = JSON.parse(text); should.exist(data); var pdfText = data.textPages.join(''); var supplyText = getSupplyText(pdfText); should.not.exist(supplyText); done(); }); }); it('should return text when supply text is available', function(done) { var filePath = path.join(__dirname, 'data/supplyStandard.json'); assert.ok(fs.existsSync(filePath, 'bill text json file not found at path: ' + filePath)); fs.readFile(filePath,'utf8', function (err, text) { should.not.exist(err); var data = JSON.parse(text); should.exist(data); var pdfText = data.textPages.join(''); pdfText = pdfText.replace(/ {2,}/g, ' '); var supplyText = getSupplyText(pdfText); should.exist(supplyText); var desiredText = 'Supply Services\n SUPPLIER National Grid\n\n\n Basic Service Variable 0.07939 x 20400 kWh 1,619.56\n Total Supply Services $ 1,619.56'; desiredText.should.eql(supplyText); done(); }); }); });