add tests to insight storage + remove used code
This commit is contained in:
parent
d511103081
commit
bd698257f9
6 changed files with 124 additions and 93 deletions
|
|
@ -46,6 +46,8 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
$scope.error = 'Invalid email or password';
|
||||
} else if ((err.toString() || '').match('Connection')) {
|
||||
$scope.error = 'Could not connect to Insight Server';
|
||||
} else if ((err.toString() || '').match('Unable')) {
|
||||
$scope.error = 'Unable to read data from the Insight Server';
|
||||
} else {
|
||||
$scope.error = 'Unknown error';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -298,32 +298,4 @@ GoogleDrive.prototype._checkHomeDir = function(cb) {
|
|||
});
|
||||
};
|
||||
|
||||
GoogleDrive.prototype.allKeys = function(cb) {
|
||||
var self = this;
|
||||
|
||||
this._checkHomeDir(function(homeId) {
|
||||
preconditions.checkState(homeId);
|
||||
|
||||
var request = gapi.client.request({
|
||||
'path': '/drive/v2/files',
|
||||
'method': 'GET',
|
||||
'params': {
|
||||
'q': "'" + homeId + "' in parents and trashed = false",
|
||||
'fields': 'items(id,title)'
|
||||
},
|
||||
});
|
||||
request.execute(function(res) {
|
||||
// console.log('[googleDrive.js.152:res:]', res); //TODO
|
||||
if (res.error)
|
||||
throw new Error(res.error.message);
|
||||
|
||||
var ret = [];
|
||||
for (var ii in res.items) {
|
||||
ret.push(res.items[ii].title);
|
||||
}
|
||||
return cb(ret);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = GoogleDrive;
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ InsightStorage.prototype._makeGetRequest = function(passphrase, key, callback) {
|
|||
return callback('PNOTFOUND: Profile not found');
|
||||
}
|
||||
if (response.statusCode !== 200) {
|
||||
return callback('Connection error');
|
||||
return callback('Unable to read item from insight');
|
||||
}
|
||||
return callback(null, body, InsightStorage.parseResponseHeaders(response.getAllResponseHeaders()));
|
||||
}
|
||||
|
|
@ -217,7 +217,7 @@ InsightStorage.prototype.removeItem = function(key, callback) {
|
|||
'Authorization': authHeader
|
||||
}
|
||||
};
|
||||
log.debug('erase ' + name);
|
||||
log.debug('Erasing: ' + key);
|
||||
this.request.get(getParams, function(err, response, body) {
|
||||
if (err) {
|
||||
return callback('Connection error');
|
||||
|
|
@ -236,14 +236,4 @@ InsightStorage.prototype.clear = function(callback) {
|
|||
callback();
|
||||
};
|
||||
|
||||
InsightStorage.prototype.allKeys = function(callback) {
|
||||
// TODO: compatibility with localStorage
|
||||
return callback(null);
|
||||
};
|
||||
|
||||
InsightStorage.prototype.getFirst = function(prefix, opts, callback) {
|
||||
// TODO: compatibility with localStorage
|
||||
return callback(null, true, true);
|
||||
};
|
||||
|
||||
module.exports = InsightStorage;
|
||||
|
|
|
|||
|
|
@ -46,38 +46,4 @@ LocalStorage.prototype.clear = function(cb) {
|
|||
return cb();
|
||||
};
|
||||
|
||||
LocalStorage.prototype.allKeys = function(cb) {
|
||||
var l = localStorage.length;
|
||||
var ret = [];
|
||||
|
||||
for(var i=0; i<l; i++)
|
||||
ret.push(localStorage.key(i));
|
||||
|
||||
return cb(null, ret);
|
||||
};
|
||||
|
||||
LocalStorage.prototype.getFirst = function(prefix, opts, cb) {
|
||||
opts = opts || {};
|
||||
var that = this;
|
||||
|
||||
this.allKeys(function(err, allKeys) {
|
||||
var keys = _.filter(allKeys, function(k) {
|
||||
if ((k === prefix) || k.indexOf(prefix) === 0) return true;
|
||||
});
|
||||
|
||||
if (keys.length === 0)
|
||||
return cb(new Error('not found'));
|
||||
|
||||
if (opts.onlyKey)
|
||||
return cb(null, null, keys[0]);
|
||||
|
||||
that.getItem(keys[0], function(err, data) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
return cb(null, data, keys[0]);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = LocalStorage;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue