Skip to content

Instantly share code, notes, and snippets.

@andrewvmail
Created May 31, 2015 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewvmail/1d50368a701ef8ae4c79 to your computer and use it in GitHub Desktop.
Save andrewvmail/1d50368a701ef8ae4c79 to your computer and use it in GitHub Desktop.
mocks
var assert = require("assert"); // node.js core module
var should = require('should');
var fs = require("fs");
var base = process.env.PWD;
var Inserter = require("../../api/services/ratesimporter/Inserter.js");
describe('Inserter', function () {
//describe('#changeHeader()', function(){
//it('it should return serviceProvider csv when passed in flowroute provider', function(done){
// Inserter.changeHeader('flowroute', function(error, result) {
//
// get_line(base + '/history/rates/flowroute.csv', 0, function(err, line){
// //console.log('The line: ' + line);
//
// var headers = line.split(',');
//
// //headers must contain Rate, Prefix, Destination
// headers.should.containEql('Rate');
// headers.should.containEql('Prefix');
// headers.should.containEql('Destination');
//
// assert('flowroute' === result, headers + 'Result is flowroute.csv');
//
// done();
// })
//
// });
//
//});
//
//it('it should return serviceProvider csv when passed in didlogic provider', function(done){
// Inserter.changeHeader('didlogic', function(error, result) {
// get_line(base + '/history/rates/didlogic.csv', 0, function(err, line){
// //console.log('The line: ' + line);
//
// var headers = line.split(',');
//
// //TODO: Remove quotes from headers clean it up
// //headers must contain Rate, Prefix, Destination
// headers.should.containEql('"Rate"');
// headers.should.containEql('"Prefix"');
// headers.should.containEql('"Destination"');
//
// assert('didlogic' === result, headers + 'Result is didlogic.csv');
//
// done();
// })
//
// });
//
//});
//});
//describe('#toJSON() > #toCouch()', function(){
// it('it should return a json object with flowroute data', function(done) {
//
// Inserter.toJSON('flowroute', function(error, result) {
// //console.log(result);
// result.should.be.json;
//
// assert(!error, 'No error when runs.');
// done();
// });
//
// });
//});
describe('#toCouch()', function () {
it('it should return a json object with flowroute data', function (done) {
var mockedData = [
{
Destination: 'DOMINICAN REPUBLIC-SANTIAGO',
Prefix: 18092427,
'First Interval': 6,
'Sub Interval': 6,
Rate: 0.02239,
Status: 'Current',
'Start Date': '2015-02-17 07:00:00',
'End Date': ''
},
{
Destination: 'DOMINICAN REPUBLIC',
Prefix: 1809241,
'First Interval': 6,
'Sub Interval': 6,
Rate: 0.0229,
Status: 'Current',
'Start Date': '2015-02-17 07:00:00',
'End Date': ''
},
{
Destination: 'DOMINICAN REPUBLIC',
Prefix: 1809233,
'First Interval': 6,
'Sub Interval': 6,
Rate: 0.02329,
Status: 'Current',
'Start Date': '2015-02-17 07:00:00',
'End Date': ''
},
{
Destination: 'DOMINICAN REPUBLIC',
Prefix: 1809226,
'First Interval': 6,
'Sub Interval': 6,
Rate: 0.02239,
Status: 'Current',
'Start Date': '2015-02-17 07:00:00',
'End Date': ''
},
{
Destination: 'DOMINICAN REPUBLIC-SANTO DOMINGO',
Prefix: 1809179,
'First Interval': 6,
'Sub Interval': 6,
Rate: 0.024329,
Status: 'Current',
'Start Date': '2015-02-17 07:00:00',
'End Date': ''
}]
Inserter.toCouch(mockedData, 'flowroute', function (error, result) {
console.log('results', result);
assert(!error, 'No error when runs.');
done();
});
});
});
//describe('#insertTest()', function () {
// it('insert everything in the database', function (done) {
//
// sails.services['ratesimporter'].run(function(error, result) {
//
// if(error) console.log(error);
//
// console.log(result);
//
// done();
//
// });
//
//
// });
//});
});
function get_line(filename, line_no, callback) {
fs.readFile(filename, function (err, data) {
if (err) throw err;
// Data is a buffer that we need to convert to a string
// Improvement: loop over the buffer and stop when the line is reached
var lines = data.toString('utf-8').split("\n");
if (+line_no > lines.length) {
return callback('File end reached without finding line', null);
}
callback(null, lines[+line_no]);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment