mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 08:52:15 -05:00
deleted local storage dao code and tests
This commit is contained in:
parent
09d4c1c56f
commit
9a7e87d33e
@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Handles generic caching of JSON objects in LocalStorage
|
||||
*/
|
||||
app.dao.LocalStorageDAO = function(window) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Stringifies an object literal to JSON and perists it
|
||||
*/
|
||||
this.persist = function(key, object) {
|
||||
var json = JSON.stringify(object);
|
||||
window.localStorage.setItem(key, json);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches a json string from local storage by its key and parses it to an object literal
|
||||
*/
|
||||
this.read = function(key) {
|
||||
var json = window.localStorage.getItem(key);
|
||||
return JSON.parse(json);
|
||||
};
|
||||
|
||||
/**
|
||||
* List all the items of a certain type in local storage
|
||||
* @param type [String] The type of item e.g. 'email'
|
||||
*/
|
||||
this.list = function(type) {
|
||||
var i, key, json, list = [];
|
||||
|
||||
for (i = 0; i < window.localStorage.length; i++) {
|
||||
key = window.localStorage.key(i);
|
||||
if (key.indexOf(type) === 0) {
|
||||
json = window.localStorage.getItem(key);
|
||||
list.push(JSON.parse(json));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes an object liter from local storage by its key (delete)
|
||||
*/
|
||||
this.remove = function(key) {
|
||||
window.localStorage.removeItem(key);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears the whole local storage cache
|
||||
*/
|
||||
this.clear = function() {
|
||||
window.localStorage.clear();
|
||||
};
|
||||
|
||||
};
|
@ -45,7 +45,6 @@
|
||||
<script src="../../src/js/crypto/crypto-batch.js"></script>
|
||||
<script src="../../src/js/crypto/crypto.js"></script>
|
||||
|
||||
<script src="../../src/js/dao/localstorage-dao.js"></script>
|
||||
<script src="../../src/js/dao/lawnchair-dao.js"></script>
|
||||
<script src="../../src/js/dao/devicestorage.js"></script>
|
||||
<script src="../../src/js/dao/cloudstorage-dao.js"></script>
|
||||
|
@ -45,7 +45,6 @@
|
||||
<script src="../../src/js/crypto/crypto-batch.js"></script>
|
||||
<script src="../../src/js/crypto/crypto.js"></script>
|
||||
|
||||
<script src="../../src/js/dao/localstorage-dao.js"></script>
|
||||
<script src="../../src/js/dao/lawnchair-dao.js"></script>
|
||||
<script src="../../src/js/dao/devicestorage.js"></script>
|
||||
<script src="../../src/js/dao/cloudstorage-dao.js"></script>
|
||||
@ -57,7 +56,6 @@
|
||||
<script src="forge-test.js"></script>
|
||||
<script src="aes-test.js"></script>
|
||||
<script src="rsa-test.js"></script>
|
||||
<script src="localstorage-dao-test.js"></script>
|
||||
<script src="lawnchair-dao-test.js"></script>
|
||||
<script src="keychain-dao-test.js"></script>
|
||||
<script src="crypto-test.js"></script>
|
||||
|
@ -1,36 +0,0 @@
|
||||
module("LocalStorage DAO");
|
||||
|
||||
test("CRUD object literal", 4, function() {
|
||||
var dao = new app.dao.LocalStorageDAO(window);
|
||||
|
||||
// clear before test
|
||||
dao.clear();
|
||||
|
||||
var key = 'type_asdf';
|
||||
var data = {
|
||||
name : 'testName',
|
||||
type : 'testType'
|
||||
};
|
||||
|
||||
// create
|
||||
dao.persist(key, data);
|
||||
|
||||
// read
|
||||
var read = dao.read(key);
|
||||
equal(data.name, read.name, 'Create, Read');
|
||||
|
||||
// list all
|
||||
var list = dao.list('type');
|
||||
ok(list.length === 1, 'List');
|
||||
|
||||
// update
|
||||
var newName = 'updatedName';
|
||||
read.name = newName;
|
||||
dao.persist(key, read);
|
||||
var updated = dao.read(key);
|
||||
equal(updated.name, newName, 'Update');
|
||||
|
||||
// delete
|
||||
dao.remove(key);
|
||||
equal(dao.read(key), null, 'Delete');
|
||||
});
|
Loading…
Reference in New Issue
Block a user