make tests work by faking storage

This commit is contained in:
Ryan X. Charles 2014-04-16 16:52:42 -03:00
parent 08f918a9a7
commit b442e110e4
2 changed files with 14 additions and 9 deletions

3
API.js
View File

@ -20,6 +20,9 @@ API.prototype._init = function(opts) {
wallet: {
requiredCopayers: opts.requiredCopayers || 3,
totalCopayers: opts.totalCopayers || 5,
},
storage: {
filename: 'copaywallet.json'
}
};

View File

@ -4,11 +4,13 @@ var chai = chai || require('chai');
var should = chai.should();
var copay = copay || require('../copay');
var API = API || copay.API;
var Storage = Storage || require('../test/mocks/FakeStorage');
describe('API', function() {
it('should have a command called "echo"', function() {
var api = new API();
var api = new API({Storage: Storage});
should.exist(api.echo);
});
@ -22,7 +24,7 @@ describe('API', function() {
})
it('should throw an error for all commands when called with wrong number of arguments', function() {
var api = new API();
var api = new API({Storage: Storage});
for (var i in API.prototype) {
var f = API.prototype[i];
if (i[0] != '_' && typeof f == 'function') {
@ -49,7 +51,7 @@ describe('API', function() {
describe('#echo', function() {
it('should echo a string', function(done) {
var api = new API();
var api = new API({Storage: Storage});
var str = 'mystr';
api.echo(str, function(err, result) {
result.should.equal(str);
@ -60,7 +62,7 @@ describe('API', function() {
describe('#echoNumber', function() {
it('should echo a number', function(done) {
var api = new API();
var api = new API({Storage: Storage});
var num = 500;
api.echoNumber(num, function(err, result) {
result.should.equal(num);
@ -72,7 +74,7 @@ describe('API', function() {
describe('#echoObject', function() {
it('should echo an object', function(done) {
var api = new API();
var api = new API({Storage: Storage});
var obj = {test:'test'};
api.echoObject(obj, function(err, result) {
result.test.should.equal(obj.test);
@ -84,7 +86,7 @@ describe('API', function() {
describe('#getArgTypes', function() {
it('should get the argTypes of echo', function(done) {
var api = new API();
var api = new API({Storage: Storage});
api.getArgTypes('echo', function(err, result) {
result[0][1].should.equal('string');
done();
@ -94,7 +96,7 @@ describe('API', function() {
describe('#getCommands', function() {
it('should get all the commands', function(done) {
var api = new API();
var api = new API({Storage: Storage});
var n = 0;
for (var i in api)
@ -110,7 +112,7 @@ describe('API', function() {
describe('#getPublicKeyRingId', function() {
it('should get a public key ring ID', function(done) {
var api = new API();
var api = new API({Storage: Storage});
api.getPublicKeyRingId(function(err, result) {
result.length.should.be.greaterThan(5);
done();
@ -120,7 +122,7 @@ describe('API', function() {
describe('#help', function() {
it('should call _cmd_getCommands', function(done) {
var api = new API();
var api = new API({Storage: Storage});
api._cmd_getCommands = function(callback) {
(typeof arguments[0]).should.equal('function');
callback(null, ['item']);