add tests to plugin.localstorage
This commit is contained in:
parent
bd698257f9
commit
5db7695d89
2 changed files with 69 additions and 8 deletions
|
|
@ -2,11 +2,16 @@
|
|||
var _ = require('lodash');
|
||||
var preconditions = require('preconditions').singleton();
|
||||
|
||||
function LocalStorage() {
|
||||
function LocalStorage(opts) {
|
||||
this.type = 'DB';
|
||||
opts = opts || {};
|
||||
|
||||
|
||||
preconditions.checkState(typeof localStorage !== 'undefined',
|
||||
'localstorage not available, cannot run plugin');
|
||||
this.ls = opts.ls
|
||||
|| ( (typeof localStorage !== 'undefined') ? localStorage : null );
|
||||
|
||||
preconditions.checkState(this.ls,
|
||||
'localstorage not available, cannot run plugin');
|
||||
};
|
||||
|
||||
LocalStorage.prototype.init = function() {
|
||||
|
|
@ -18,31 +23,31 @@ LocalStorage.prototype.setCredentials = function(email, password, opts) {
|
|||
};
|
||||
|
||||
LocalStorage.prototype.getItem = function(k,cb) {
|
||||
return cb(null, localStorage.getItem(k));
|
||||
return cb(null, this.ls.getItem(k));
|
||||
};
|
||||
|
||||
/**
|
||||
* Same as setItem, but fails if an item already exists
|
||||
*/
|
||||
LocalStorage.prototype.createItem = function(name, value, callback) {
|
||||
if (localStorage.getItem(name)) {
|
||||
if (this.ls.getItem(name)) {
|
||||
return callback('EEXISTS');
|
||||
}
|
||||
return this.setItem(name, value, callback);
|
||||
};
|
||||
|
||||
LocalStorage.prototype.setItem = function(k,v,cb) {
|
||||
localStorage.setItem(k,v);
|
||||
this.ls.setItem(k,v);
|
||||
return cb();
|
||||
};
|
||||
|
||||
LocalStorage.prototype.removeItem = function(k,cb) {
|
||||
localStorage.removeItem(k);
|
||||
this.ls.removeItem(k);
|
||||
return cb();
|
||||
};
|
||||
|
||||
LocalStorage.prototype.clear = function(cb) {
|
||||
localStorage.clear();
|
||||
this.ls.clear();
|
||||
return cb();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue