refactor testing setup/teardown in helpers
This commit is contained in:
parent
c1a456d32a
commit
7042e240f8
|
@ -8,6 +8,9 @@ var sinon = require('sinon');
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
var log = require('npmlog');
|
var log = require('npmlog');
|
||||||
log.debug = log.verbose;
|
log.debug = log.verbose;
|
||||||
|
var tingodb = require('tingodb')({
|
||||||
|
memStore: true
|
||||||
|
});
|
||||||
|
|
||||||
var Bitcore = require('bitcore-lib');
|
var Bitcore = require('bitcore-lib');
|
||||||
|
|
||||||
|
@ -16,16 +19,60 @@ var Utils = Common.Utils;
|
||||||
var Constants = Common.Constants;
|
var Constants = Common.Constants;
|
||||||
var Defaults = Common.Defaults;
|
var Defaults = Common.Defaults;
|
||||||
|
|
||||||
|
var Storage = require('../../lib/storage');
|
||||||
var Model = require('../../lib/model');
|
var Model = require('../../lib/model');
|
||||||
var WalletService = require('../../lib/server');
|
var WalletService = require('../../lib/server');
|
||||||
var TestData = require('../testdata');
|
var TestData = require('../testdata');
|
||||||
|
|
||||||
var blockchainExplorer;
|
var storage, blockchainExplorer;
|
||||||
|
|
||||||
var helpers = {};
|
var helpers = {};
|
||||||
|
|
||||||
helpers.setBlockchainExplorer = function(bce) {
|
var useMongoDb = !!process.env.USE_MONGO_DB;
|
||||||
blockchainExplorer = bce;
|
|
||||||
|
helpers.before = function(cb) {
|
||||||
|
function getDb(cb) {
|
||||||
|
if (useMongoDb) {
|
||||||
|
var mongodb = require('mongodb');
|
||||||
|
mongodb.MongoClient.connect('mongodb://localhost:27017/bws_test', function(err, db) {
|
||||||
|
if (err) throw err;
|
||||||
|
return cb(db);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var db = new tingodb.Db('./db/test', {});
|
||||||
|
return cb(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getDb(function(db) {
|
||||||
|
storage = new Storage({
|
||||||
|
db: db
|
||||||
|
});
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
helpers.beforeEach = function(cb) {
|
||||||
|
if (!storage.db) return cb();
|
||||||
|
storage.db.dropDatabase(function(err) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
blockchainExplorer = sinon.stub();
|
||||||
|
WalletService.initialize({
|
||||||
|
storage: storage,
|
||||||
|
blockchainExplorer: blockchainExplorer,
|
||||||
|
}, cb);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
helpers.after = function(cb) {
|
||||||
|
WalletService.shutDown(cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
helpers.getBlockchainExplorer = function() {
|
||||||
|
return blockchainExplorer;
|
||||||
|
};
|
||||||
|
|
||||||
|
helpers.getStorage = function() {
|
||||||
|
return storage;
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.signMessage = function(text, privKey) {
|
helpers.signMessage = function(text, privKey) {
|
||||||
|
|
|
@ -10,11 +10,6 @@ var should = chai.should();
|
||||||
var log = require('npmlog');
|
var log = require('npmlog');
|
||||||
log.debug = log.verbose;
|
log.debug = log.verbose;
|
||||||
|
|
||||||
var fs = require('fs');
|
|
||||||
var tingodb = require('tingodb')({
|
|
||||||
memStore: true
|
|
||||||
});
|
|
||||||
|
|
||||||
var Bitcore = require('bitcore-lib');
|
var Bitcore = require('bitcore-lib');
|
||||||
|
|
||||||
var Common = require('../../lib/common');
|
var Common = require('../../lib/common');
|
||||||
|
@ -22,67 +17,30 @@ var Utils = Common.Utils;
|
||||||
var Constants = Common.Constants;
|
var Constants = Common.Constants;
|
||||||
var Defaults = Common.Defaults;
|
var Defaults = Common.Defaults;
|
||||||
|
|
||||||
var Storage = require('../../lib/storage');
|
|
||||||
var Model = require('../../lib/model');
|
var Model = require('../../lib/model');
|
||||||
|
|
||||||
var WalletService = require('../../lib/server');
|
var WalletService = require('../../lib/server');
|
||||||
var EmailService = require('../../lib/emailservice');
|
var EmailService = require('../../lib/emailservice');
|
||||||
|
|
||||||
var TestData = require('../testdata');
|
var TestData = require('../testdata');
|
||||||
|
|
||||||
var helpers = require('./helpers');
|
var helpers = require('./helpers');
|
||||||
|
var storage, blockchainExplorer;
|
||||||
|
|
||||||
var CLIENT_VERSION = 'bwc-0.1.1';
|
var CLIENT_VERSION = 'bwc-0.1.1';
|
||||||
|
|
||||||
var storage, blockchainExplorer;
|
|
||||||
|
|
||||||
var useMongoDb = !!process.env.USE_MONGO_DB;
|
|
||||||
|
|
||||||
function initStorage(cb) {
|
|
||||||
function getDb(cb) {
|
|
||||||
if (useMongoDb) {
|
|
||||||
var mongodb = require('mongodb');
|
|
||||||
mongodb.MongoClient.connect('mongodb://localhost:27017/bws_test', function(err, db) {
|
|
||||||
if (err) throw err;
|
|
||||||
return cb(db);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var db = new tingodb.Db('./db/test', {});
|
|
||||||
return cb(db);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getDb(function(db) {
|
|
||||||
storage = new Storage({
|
|
||||||
db: db
|
|
||||||
});
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function resetStorage(cb) {
|
|
||||||
if (!storage.db) return cb();
|
|
||||||
storage.db.dropDatabase(function(err) {
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
describe('Wallet service', function() {
|
describe('Wallet service', function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
initStorage(done);
|
helpers.before(done);
|
||||||
});
|
});
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
resetStorage(function() {
|
helpers.beforeEach(function(err) {
|
||||||
blockchainExplorer = sinon.stub();
|
storage = helpers.getStorage();
|
||||||
helpers.setBlockchainExplorer(blockchainExplorer);
|
blockchainExplorer = helpers.getBlockchainExplorer();
|
||||||
WalletService.initialize({
|
done();
|
||||||
storage: storage,
|
|
||||||
blockchainExplorer: blockchainExplorer,
|
|
||||||
}, done);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
after(function(done) {
|
after(function(done) {
|
||||||
WalletService.shutDown(done);
|
helpers.after(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Email notifications', function() {
|
describe('Email notifications', function() {
|
||||||
|
@ -1531,7 +1489,6 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('Preferences', function() {
|
describe('Preferences', function() {
|
||||||
var server, wallet;
|
var server, wallet;
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
|
|
Loading…
Reference in New Issue