Commit 1b82849f authored by Romain Courteaud's avatar Romain Courteaud

Add tests for DocumentStorage

parent 96d5d045
/*jslint nomen: true*/ /*jslint nomen: true*/
/*global console, Blob, atob, btoa*/ /*global Blob, atob, btoa*/
(function (jIO, Blob, atob, btoa) { (function (jIO, Blob, atob, btoa) {
"use strict"; "use strict";
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
"_attachment": getSubAttachmentIdFromParam(param) "_attachment": getSubAttachmentIdFromParam(param)
}) })
.push(function (blob) { .push(function (blob) {
return jIO.util.readBlobAsText(blob); return jIO.util.readBlobAsText(blob.data);
}) })
.push(function (text) { .push(function (text) {
return JSON.parse(text.target.result); return JSON.parse(text.target.result);
...@@ -54,9 +54,16 @@ ...@@ -54,9 +54,16 @@
if (document._attachments.hasOwnProperty(key)) { if (document._attachments.hasOwnProperty(key)) {
if (ATTACHMENT_REGEXP.test(key)) { if (ATTACHMENT_REGEXP.test(key)) {
exec = ATTACHMENT_REGEXP.exec(key); exec = ATTACHMENT_REGEXP.exec(key);
try {
if (atob(exec[1]) === param._id) { if (atob(exec[1]) === param._id) {
attachments[atob(exec[2])] = {}; attachments[atob(exec[2])] = {};
} }
} catch (error) {
// Check if unable to decode base64 data
if (!error instanceof ReferenceError) {
throw error;
}
}
} }
} }
} }
...@@ -67,17 +74,6 @@ ...@@ -67,17 +74,6 @@
}); });
}; };
DocumentStorage.prototype.post = function (param) {
var doc_id = param._id;
if (doc_id === undefined) {
doc_id = jIO.util.generateUuid();
}
param._id = doc_id;
return this.put(param);
};
DocumentStorage.prototype.put = function (param) { DocumentStorage.prototype.put = function (param) {
var doc_id = param._id; var doc_id = param._id;
...@@ -116,10 +112,17 @@ ...@@ -116,10 +112,17 @@
for (key in document._attachments) { for (key in document._attachments) {
if (document._attachments.hasOwnProperty(key)) { if (document._attachments.hasOwnProperty(key)) {
if (DOCUMENT_REGEXP.test(key)) { if (DOCUMENT_REGEXP.test(key)) {
try {
result.push({ result.push({
id: atob(DOCUMENT_REGEXP.exec(key)[1]), id: atob(DOCUMENT_REGEXP.exec(key)[1]),
value: {} value: {}
}); });
} catch (error) {
// Check if unable to decode base64 data
if (!error instanceof ReferenceError) {
throw error;
}
}
} }
} }
} }
......
This diff is collapsed.
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