Commit f19a4f95 authored by Tristan Cavelier's avatar Tristan Cavelier

fix test bugs on jio localstorage.js

parent b94e9b36
...@@ -194,7 +194,7 @@ var newLocalStorage = function (spec, my) { ...@@ -194,7 +194,7 @@ var newLocalStorage = function (spec, my) {
doc); doc);
that.success({ that.success({
"ok":true, "ok":true,
"_id":command.getDocId()+"/"+command.getAttachmentId() "id":command.getDocId()+"/"+command.getAttachmentId()
}); });
}); });
}; };
...@@ -249,38 +249,57 @@ var newLocalStorage = function (spec, my) { ...@@ -249,38 +249,57 @@ var newLocalStorage = function (spec, my) {
*/ */
that.remove = function (command) { that.remove = function (command) {
setTimeout (function () { setTimeout (function () {
var doc; var doc, error;
error = function (word) {
that.error({
"status": 404,
"statusText": "Not Found",
"error": "not_found",
"message": word+" not found",
"reason": "missing"
});
};
doc = localstorage.getItem( doc = localstorage.getItem(
priv.localpath + "/" + command.getDocId()); priv.localpath + "/" + command.getDocId());
if (typeof command.getAttachmentId() === "string") { if (typeof command.getAttachmentId() === "string") {
// seeking for an attachment
localstorage.removeItem(
priv.localpath + "/" + command.getDocId() + "/" +
command.getAttachmentId());
// remove attachment from document // remove attachment from document
if (doc !== null && typeof doc === "object" && if (doc !== null && typeof doc === "object" &&
typeof doc["_attachments"] === "object") { typeof doc["_attachments"] === "object") {
delete doc["_attachments"][command.getAttachmentId()]; if (typeof doc["_attachments"][
if (priv.objectIsEmpty(doc["_attachments"])) { command.getAttachmentId()] === "object") {
delete doc["_attachments"]; delete doc["_attachments"][command.getAttachmentId()];
if (priv.objectIsEmpty(doc["_attachments"])) {
delete doc["_attachments"];
}
localstorage.setItem(
priv.localpath + "/" + command.getDocId(),
doc);
localstorage.removeItem(
priv.localpath + "/" + command.getDocId() + "/" +
command.getAttachmentId());
that.success({
"ok": true,
"id": command.getDocId()+"/"+
command.getAttachmentId()
});
} else {
error("Attachment");
} }
localstorage.setItem( } else {
priv.localpath + "/" + command.getDocId(), error("Document");
doc);
} }
that.success({
"ok": true,
"id": command.getDocId()+"/"+command.getAttachmentId()
});
} else { } else {
// seeking for a document // seeking for a document
var attachment_list = [], i; var attachment_list = [], i;
if (doc !== null && typeof doc === "object" && if (doc !== null && typeof doc === "object") {
typeof doc["_attachments"] === "object") { if (typeof doc["_attachments"] === "object") {
// prepare list of attachments // prepare list of attachments
for (i in doc["_attachments"]) { for (i in doc["_attachments"]) {
attachment_list.push(i); attachment_list.push(i);
}
} }
} else {
return error("Document");
} }
localstorage.removeItem( localstorage.removeItem(
priv.localpath + "/" + command.getDocId()); priv.localpath + "/" + command.getDocId());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment