Browse Source

cleanup

activeAddress
Ivan Socolsky 10 years ago
parent
commit
d7ea3e48bb
  1. 6
      lib/storage.js
  2. 55
      test/integration/server.js
  3. 9
      test/storage.js

6
lib/storage.js

@ -19,13 +19,15 @@ var collections = {
NOTIFICATIONS: 'notifications', NOTIFICATIONS: 'notifications',
}; };
var Storage = function() {}; var Storage = function(opts) {
opts = opts || {};
this.db = opts.db;
};
Storage.prototype.connect = function(opts, cb) { Storage.prototype.connect = function(opts, cb) {
var self = this; var self = this;
opts = opts || {}; opts = opts || {};
this.db = opts.db;
if (this.db) return cb(); if (this.db) return cb();

55
test/integration/server.js

@ -211,44 +211,43 @@ helpers.createAddresses = function(server, wallet, main, change, cb) {
var db, storage, blockchainExplorer; var db, storage, blockchainExplorer;
function openDb(cb) { function openDb(cb) {
function dropDb(cb) { var url = 'mongodb://localhost:27017/bws';
db.dropDatabase(function(err) { mongodb.MongoClient.connect(url, function(err, _db) {
should.not.exist(err); should.not.exist(err);
db = _db;
return cb(); return cb();
}); });
}; };
if (db) {
return dropDb(cb); function resetDb(cb) {
} else { if (!db) return cb();
var url = 'mongodb://localhost:27017/bws'; db.dropDatabase(function(err) {
mongodb.MongoClient.connect(url, function(err, _db) {
should.not.exist(err); should.not.exist(err);
db = _db; return cb();
return dropDb(cb);
}); });
}
}; };
function closeDb(cb) { function closeDb(cb) {
if (db) { if (!db) return cb();
db.close(true, function(err) { db.close(true, function(err) {
should.not.exist(err); should.not.exist(err);
db = null; db = null;
return cb(); return cb();
}); });
} else {
return cb();
}
}; };
describe('Wallet service', function() { describe('Wallet service', function() {
beforeEach(function(done) { before(function(done) {
openDb(function() { openDb(function() {
storage = new Storage(); storage = new Storage({
storage.connect({
db: db db: db
}, function(err) { });
should.not.exist(err); done();
});
});
beforeEach(function(done) {
resetDb(function() {
blockchainExplorer = sinon.stub(); blockchainExplorer = sinon.stub();
WalletService.initialize({ WalletService.initialize({
@ -259,7 +258,6 @@ describe('Wallet service', function() {
done(); done();
}); });
}); });
});
after(function(done) { after(function(done) {
closeDb(done); closeDb(done);
}); });
@ -3052,17 +3050,21 @@ describe('Wallet service', function() {
describe('Blockchain monitor', function() { describe('Blockchain monitor', function() {
var addressSubscriber; var addressSubscriber;
before(function(done) {
openDb(function() {
storage = new Storage({
db: db
});
done();
});
});
beforeEach(function(done) { beforeEach(function(done) {
addressSubscriber = sinon.stub(); addressSubscriber = sinon.stub();
addressSubscriber.subscribe = sinon.stub(); addressSubscriber.subscribe = sinon.stub();
sinon.stub(BlockchainMonitor.prototype, '_getAddressSubscriber').onFirstCall().returns(addressSubscriber); sinon.stub(BlockchainMonitor.prototype, '_getAddressSubscriber').onFirstCall().returns(addressSubscriber);
openDb(function() { resetDb(function() {
storage = new Storage();
storage.connect({
db: db
}, function(err) {
should.not.exist(err);
blockchainExplorer = sinon.stub(); blockchainExplorer = sinon.stub();
WalletService.initialize({ WalletService.initialize({
@ -3074,7 +3076,6 @@ describe('Blockchain monitor', function() {
done(); done();
}); });
}); });
});
afterEach(function() { afterEach(function() {
BlockchainMonitor.prototype._getAddressSubscriber.restore(); BlockchainMonitor.prototype._getAddressSubscriber.restore();
}); });

9
test/storage.js

@ -12,7 +12,7 @@ var Model = require('../lib/model');
function initDb(cb) { function initDb(cb) {
var url = 'mongodb://localhost:27017/bws'; var url = 'mongodb://localhost:27017';
mongodb.MongoClient.connect(url, function(err, db) { mongodb.MongoClient.connect(url, function(err, db) {
should.not.exist(err); should.not.exist(err);
db.dropDatabase(function(err) { db.dropDatabase(function(err) {
@ -27,13 +27,10 @@ describe('Storage', function() {
beforeEach(function(done) { beforeEach(function(done) {
initDb(function(err, db) { initDb(function(err, db) {
should.not.exist(err); should.not.exist(err);
storage = new Storage(); storage = new Storage({
storage.connect({
db: db db: db
}, function(err) {
should.not.exist(err);
done();
}); });
done();
}); });
}); });
describe('Store & fetch wallet', function() { describe('Store & fetch wallet', function() {

Loading…
Cancel
Save