Commit 3ad7eaba authored by Tristan Cavelier's avatar Tristan Cavelier

revisionstorage putAttachment unit tests done

parent c1a8aff1
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
}(['jio', 'sha256'], function (jIO, sha256) { }(['jio', 'sha256'], function (jIO, sha256) {
"use strict"; "use strict";
var tool = {
"readBlobAsBinaryString": jIO.util.readBlobAsBinaryString,
"uniqueJSONStringify": jIO.util.uniqueJSONStringify
};
jIO.addStorage("revision", function (spec) { jIO.addStorage("revision", function (spec) {
var that = this, priv = {}; var that = this, priv = {};
...@@ -225,7 +230,8 @@ ...@@ -225,7 +230,8 @@
delete doc._rev; delete doc._rev;
delete doc._revs; delete doc._revs;
delete doc._revs_info; delete doc._revs_info;
string = JSON.stringify(doc) + JSON.stringify(revision_history) + string = tool.uniqueJSONStringify(doc) +
tool.uniqueJSONStringify(revision_history) +
JSON.stringify(deleted_flag ? true : false); JSON.stringify(deleted_flag ? true : false);
revision_history.start += 1; revision_history.start += 1;
revision_history.ids.unshift(priv.hashCode(string)); revision_history.ids.unshift(priv.hashCode(string));
...@@ -389,6 +395,7 @@ ...@@ -389,6 +395,7 @@
delete doc._attachment; delete doc._attachment;
delete doc._data; delete doc._data;
delete doc._mimetype; delete doc._mimetype;
delete doc._content_type;
delete doc._rev; delete doc._rev;
delete doc._revs; delete doc._revs;
delete doc._revs_info; delete doc._revs_info;
...@@ -428,7 +435,7 @@ ...@@ -428,7 +435,7 @@
result_list.push({ result_list.push({
"_attachment": attachment_id, "_attachment": attachment_id,
"_data": response.data, "_data": response.data,
"_mimetype": attachment_meta.content_type "_content_type": attachment_meta.content_type
}); });
if (count === 0) { if (count === 0) {
state = "finished"; state = "finished";
...@@ -625,7 +632,7 @@ ...@@ -625,7 +632,7 @@
"missing" "missing"
), undefined); ), undefined);
} }
res_doc = {"data":{}}; res_doc = {"data": {}};
} else { } else {
err.message = "Cannot get document"; err.message = "Cannot get document";
return onEnd(err, undefined); return onEnd(err, undefined);
...@@ -821,6 +828,10 @@ ...@@ -821,6 +828,10 @@
that.putAttachment = function (command, param, option) { that.putAttachment = function (command, param, option) {
tool.readBlobAsBinaryString(param._blob).then(function (event) {
param._content_type = param._blob.type;
param._data = event.target.result;
delete param._blob;
priv.revisionGenericRequest( priv.revisionGenericRequest(
command, command,
param, param,
...@@ -830,18 +841,21 @@ ...@@ -830,18 +841,21 @@
"attachment_id": param._attachment, "attachment_id": param._attachment,
"add_to_attachment_list": { "add_to_attachment_list": {
"_attachment": param._attachment, "_attachment": param._attachment,
"_mimetype": param._blob.type, "_content_type": param._content_type,
"_data": param._blob "_data": param._data
}, },
"putAttachment": true "putAttachment": true
}, },
function (err) { function (err, response) {
if (err) { if (err) {
return command.error(err); return command.error(err);
} }
command.success(); command.success({"rev": response.rev});
} }
); );
}, function () {
command.error("conflict", "broken blob", "Cannot read data to put");
});
}; };
that.remove = function (command, param, option) { that.remove = function (command, param, option) {
......
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