Commit 21fc131a authored by Tristan Cavelier's avatar Tristan Cavelier

revisionstorage get{,Attachment} unit tests done

parent 3ad7eaba
...@@ -503,7 +503,7 @@ ...@@ -503,7 +503,7 @@
priv.notFoundError = function (message, reason) { priv.notFoundError = function (message, reason) {
return { return {
"status": "not_found", "status": 404,
"message": message, "message": message,
"reason": reason "reason": reason
}; };
...@@ -511,7 +511,7 @@ ...@@ -511,7 +511,7 @@
priv.conflictError = function (message, reason) { priv.conflictError = function (message, reason) {
return { return {
"status": "conflict", "status": 409,
"message": message, "message": message,
"reason": reason "reason": reason
}; };
...@@ -654,7 +654,7 @@ ...@@ -654,7 +654,7 @@
if (option.revs_info === true) { if (option.revs_info === true) {
res_doc._revs_info = doc._revs_info; res_doc._revs_info = doc._revs_info;
} }
return onEnd(undefined, res_doc); return onEnd(undefined, {"data": res_doc});
} }
if (specific_parameter.putAttachment || if (specific_parameter.putAttachment ||
specific_parameter.removeAttachment) { specific_parameter.removeAttachment) {
...@@ -687,7 +687,7 @@ ...@@ -687,7 +687,7 @@
if (attachment_list[i] && if (attachment_list[i] &&
doc._attachment === doc._attachment ===
attachment_list[i]._attachment) { attachment_list[i]._attachment) {
return onEnd(undefined, attachment_list[i]._data); return onEnd(undefined, {"data": attachment_list[i]._data});
} }
} }
return onEnd(priv.notFoundError( return onEnd(priv.notFoundError(
......
...@@ -949,200 +949,294 @@ ...@@ -949,200 +949,294 @@
}); });
// test("Get", function () { test("Get & GetAttachment", function () {
// var o = generateTools(); var shared = {}, jio, jio_local;
// o.jio = jIO.newJio({ shared.workspace = {};
// "type": "revision", shared.local_storage_description = {
// "sub_storage": { "type": "local",
// "type": "local", "username": "revision get",
// "username": "urevget", "mode": "memory"
// "application_name": "arevget" };
// }
// });
// o.localpath = "jio/localstorage/urevget/arevget";
// // get inexistent document jio = jIO.createJIO({
// o.spy(o, "status", 404, "Get inexistent document (winner)" + "type": "revision",
// " -> 404 Not Found"); "sub_storage": shared.local_storage_description
// o.jio.get({"_id": "get1"}, o.f); }, {"workspace": shared.workspace});
// o.tick(o);
// // get inexistent attachment jio_local = jIO.createJIO(shared.local_storage_description, {
// o.spy(o, "status", 404, "Get inexistent attachment (winner)" + "workspace": shared.workspace
// " -> 404 Not Found"); });
// o.jio.getAttachment({"_id": "get1", "_attachment": "get2"}, o.f);
// o.tick(o);
// // adding a document stop();
// o.doctree = {"children": [{
// "rev": "1-rev1",
// "status": "available",
// "children": []
// }]};
// o.doc_myget1 = {"_id": "get1.1-rev1", "title": "myGet1"};
// util.jsonlocalstorage.setItem(
// o.localpath + "/get1.revision_tree.json",
// o.doctree
// );
// util.jsonlocalstorage.setItem(o.localpath + "/get1.1-rev1", o.doc_myget1);
// // get document
// o.doc_myget1_cloned = deepClone(o.doc_myget1);
// o.doc_myget1_cloned._id = "get1";
// o.doc_myget1_cloned._rev = "1-rev1";
// o.doc_myget1_cloned._revisions = {"start": 1, "ids": ["rev1"]};
// o.doc_myget1_cloned._revs_info = [{
// "rev": "1-rev1",
// "status": "available"
// }];
// o.spy(o, "value", o.doc_myget1_cloned, "Get document (winner)");
// o.jio.get({"_id": "get1"}, {
// "revs_info": true,
// "revs": true,
// "conflicts": true
// }, o.f);
// o.tick(o);
// // adding two documents success(jio.get({"_id": "get1"})).then(function (answer) {
// o.doctree = {"children": [{
// "rev": "1-rev1",
// "status": "available",
// "children": []
// }, {
// "rev": "1-rev2",
// "status": "available",
// "children": [{
// "rev": "2-rev3",
// "status": "available",
// "children": []
// }]
// }]};
// o.doc_myget2 = {"_id": "get1.1-rev2", "title": "myGet2"};
// o.doc_myget3 = {"_id": "get1.2-rev3", "title": "myGet3"};
// util.jsonlocalstorage.setItem(
// o.localpath + "/get1.revision_tree.json",
// o.doctree
// );
// util.jsonlocalstorage.setItem(o.localpath + "/get1.1-rev2", o.doc_myget2);
// util.jsonlocalstorage.setItem(o.localpath + "/get1.2-rev3", o.doc_myget3);
// // get document
// o.doc_myget3_cloned = deepClone(o.doc_myget3);
// o.doc_myget3_cloned._id = "get1";
// o.doc_myget3_cloned._rev = "2-rev3";
// o.doc_myget3_cloned._revisions = {"start": 2, "ids": ["rev3", "rev2"]};
// o.doc_myget3_cloned._revs_info = [{
// "rev": "2-rev3",
// "status": "available"
// }, {
// "rev": "1-rev2",
// "status": "available"
// }];
// o.doc_myget3_cloned._conflicts = ["1-rev1"];
// o.spy(o, "value", o.doc_myget3_cloned,
// "Get document (winner, after posting another one)");
// o.jio.get({"_id": "get1"},
// {"revs_info": true, "revs": true, "conflicts": true},
// o.f);
// o.tick(o);
// // get inexistent specific document deepEqual(answer, {
// o.spy(o, "status", 404, "Get document (inexistent specific revision)" + "error": "not_found",
// " -> 404 Not Found"); "id": "get1",
// o.jio.get({"_id": "get1", "_rev": "1-rev0"}, { "message": "Document not found",
// "revs_info": true, "method": "get",
// "revs": true, "reason": "missing",
// "conflicts": true, "result": "error",
// }, o.f); "status": 404,
// o.tick(o); "statusText": "Not Found"
}, "Get inexistent document (winner) -> 404 Not Found");
// // get specific document return success(jio.getAttachment({"_id": "get1", "_attachment": "get2"}));
// o.doc_myget2_cloned = deepClone(o.doc_myget2);
// o.doc_myget2_cloned._id = "get1";
// o.doc_myget2_cloned._rev = "1-rev2";
// o.doc_myget2_cloned._revisions = {"start": 1, "ids": ["rev2"]};
// o.doc_myget2_cloned._revs_info = [{
// "rev": "1-rev2",
// "status": "available"
// }];
// o.doc_myget2_cloned._conflicts = ["1-rev1"];
// o.spy(o, "value", o.doc_myget2_cloned, "Get document (specific revision)");
// o.jio.get({"_id": "get1", "_rev": "1-rev2"}, {
// "revs_info": true,
// "revs": true,
// "conflicts": true,
// }, o.f);
// o.tick(o);
// // adding an attachment }).then(function (answer) {
// o.attmt_myget3 = {
// "get2": {
// "length": 3,
// "digest": "md5-dontcare",
// "content_type": "oh/yeah"
// }
// };
// o.doc_myget3._attachments = o.attmt_myget3;
// util.jsonlocalstorage.setItem(o.localpath + "/get1.2-rev3", o.doc_myget3);
// util.jsonlocalstorage.setItem(o.localpath + "/get1.2-rev3/get2", "abc");
// // get attachment winner deepEqual(answer, {
// o.spy(o, "value", "abc", "Get attachment (winner)"); "attachment": "get2",
// o.jio.getAttachment({"_id": "get1", "_attachment": "get2"}, o.f); "error": "not_found",
// o.tick(o); "id": "get1",
"message": "Document not found",
"method": "getAttachment",
"reason": "missing",
"result": "error",
"status": 404,
"statusText": "Not Found"
}, "Get inexistent attachment (winner) -> 404 Not Found");
// // get inexistent attachment specific rev // adding a document
// o.spy(o, "status", 404, "Get inexistent attachment (specific revision)" + shared.doctree = {
// " -> 404 Not Found"); "_id": "get1.revision_tree.json",
// o.jio.getAttachment({ "children": JSON.stringify([{
// "_id": "get1", "rev": "1-rev1",
// "_attachment": "get2", "status": "available",
// "_rev": "1-rev1" "children": []
// }, { }])
// "revs_info": true, };
// "revs": true, shared.doc_myget1 = {"_id": "get1.1-rev1", "title": "myGet1"};
// "conflicts": true,
// }, o.f);
// o.tick(o);
// // get attachment specific rev
// o.spy(o, "value", "abc", "Get attachment (specific revision)");
// o.jio.getAttachment({
// "_id": "get1",
// "_attachment": "get2",
// "_rev": "2-rev3"
// }, {
// "revs_info": true,
// "revs": true,
// "conflicts": true,
// }, o.f);
// o.tick(o);
// // get document with attachment (specific revision) return jio_local.put(shared.doctree);
// delete o.doc_myget2_cloned._attachments; }).then(function () {
// o.spy(o, "value", o.doc_myget2_cloned, return jio_local.put(shared.doc_myget1);
// "Get document which have an attachment (specific revision)"); }).then(function () {
// o.jio.get({"_id": "get1", "_rev": "1-rev2"}, {
// "revs_info": true,
// "revs": true,
// "conflicts": true
// }, o.f);
// o.tick(o);
// // get document with attachment (winner) // get document
// o.doc_myget3_cloned._attachments = o.attmt_myget3; shared.doc_myget1_cloned = tool.deepClone(shared.doc_myget1);
// o.spy(o, "value", o.doc_myget3_cloned, shared.doc_myget1_cloned._id = "get1";
// "Get document which have an attachment (winner)"); shared.doc_myget1_cloned._rev = "1-rev1";
// o.jio.get({"_id": "get1"}, shared.doc_myget1_cloned._revisions = {"start": 1, "ids": ["rev1"]};
// {"revs_info": true, "revs": true, "conflicts": true}, shared.doc_myget1_cloned._revs_info = [{
// o.f); "rev": "1-rev1",
// o.tick(o); "status": "available"
}];
return jio.get({"_id": "get1"}, {
"revs_info": true,
"revs": true,
"conflicts": true
});
// util.closeAndcleanUpJio(o.jio); }).then(function (answer) {
// }); deepEqual(answer.data, shared.doc_myget1_cloned, "Get document (winner)");
// adding two documents
shared.doctree = {
"_id": "get1.revision_tree.json",
"children": JSON.stringify([{
"rev": "1-rev1",
"status": "available",
"children": []
}, {
"rev": "1-rev2",
"status": "available",
"children": [{
"rev": "2-rev3",
"status": "available",
"children": []
}]
}])
};
shared.doc_myget2 = {"_id": "get1.1-rev2", "title": "myGet2"};
shared.doc_myget3 = {"_id": "get1.2-rev3", "title": "myGet3"};
return jio_local.put(shared.doctree);
}).then(function () {
return jio_local.put(shared.doc_myget2);
}).then(function () {
return jio_local.put(shared.doc_myget3);
}).then(function () {
// get document
shared.doc_myget3_cloned = tool.deepClone(shared.doc_myget3);
shared.doc_myget3_cloned._id = "get1";
shared.doc_myget3_cloned._rev = "2-rev3";
shared.doc_myget3_cloned._revisions =
{"start": 2, "ids": ["rev3", "rev2"]};
shared.doc_myget3_cloned._revs_info = [{
"rev": "2-rev3",
"status": "available"
}, {
"rev": "1-rev2",
"status": "available"
}];
shared.doc_myget3_cloned._conflicts = ["1-rev1"];
return jio.get({"_id": "get1"}, {
"revs_info": true,
"revs": true,
"conflicts": true
});
}).then(function (answer) {
deepEqual(answer.data,
shared.doc_myget3_cloned,
"Get document (winner, after posting another one)");
return success(jio.get({"_id": "get1", "_rev": "1-rev0"}, {
"revs_info": true,
"revs": true,
"conflicts": true
}));
}).then(function (answer) {
deepEqual(answer, {
"error": "not_found",
"id": "get1",
"message": "Unable to find the document",
"method": "get",
"reason": "missing",
"result": "error",
"status": 404,
"statusText": "Not Found"
}, "Get document (inexistent specific revision)");
// get specific document
shared.doc_myget2_cloned = tool.deepClone(shared.doc_myget2);
shared.doc_myget2_cloned._id = "get1";
shared.doc_myget2_cloned._rev = "1-rev2";
shared.doc_myget2_cloned._revisions = {"start": 1, "ids": ["rev2"]};
shared.doc_myget2_cloned._revs_info = [{
"rev": "1-rev2",
"status": "available"
}];
shared.doc_myget2_cloned._conflicts = ["1-rev1"];
return jio.get({"_id": "get1", "_rev": "1-rev2"}, {
"revs_info": true,
"revs": true,
"conflicts": true
});
}).then(function (answer) {
deepEqual(answer.data,
shared.doc_myget2_cloned,
"Get document (specific revision)");
// adding an attachment
shared.attmt_myget3 = {
"get2": {
"length": 3,
"digest": "sha256-ba7816bf8f01cfea414140de5dae2223b00361a3" +
"96177a9cb410ff61f20015ad",
"content_type": "oh/yeah"
}
};
shared.doc_myget3._attachments = shared.attmt_myget3;
return jio_local.putAttachment({
"_id": shared.doc_myget3._id,
"_attachment": "get2",
"_data": "abc",
"_content_type": "oh/yeah"
});
}).then(function () {
return jio.getAttachment({"_id": "get1", "_attachment": "get2"});
}).then(function (answer) {
return tool.readBlobAsBinaryString(answer.data);
}).then(function (event) {
deepEqual(event.target.result, "abc", "Get attachment (winner)");
// get inexistent attachment specific rev
return success(jio.getAttachment({
"_id": "get1",
"_attachment": "get2",
"_rev": "1-rev1"
}, {
"revs_info": true,
"revs": true,
"conflicts": true
}));
}).then(function (answer) {
deepEqual(answer, {
"attachment": "get2",
"error": "not_found",
"id": "get1",
"message": "Unable to get an inexistent attachment",
"method": "getAttachment",
"reason": "missing",
"result": "error",
"status": 404,
"statusText": "Not Found"
}, "Get inexistent attachment (specific revision) -> 404 Not Found");
return jio.getAttachment({
"_id": "get1",
"_attachment": "get2",
"_rev": "2-rev3"
}, {
"revs_info": true,
"revs": true,
"conflicts": true
});
}).then(function (answer) {
return tool.readBlobAsBinaryString(answer.data);
}).then(function (event) {
deepEqual(event.target.result,
"abc",
"Get attachment (specific revision)");
// get document with attachment (specific revision)
delete shared.doc_myget2_cloned._attachments;
return jio.get({"_id": "get1", "_rev": "1-rev2"}, {
"revs_info": true,
"revs": true,
"conflicts": true
});
}).then(function (answer) {
deepEqual(answer.data,
shared.doc_myget2_cloned,
"Get document which have an attachment (specific revision)");
// get document with attachment (winner)
shared.doc_myget3_cloned._attachments = shared.attmt_myget3;
return jio.get({"_id": "get1"}, {
"revs_info": true,
"revs": true,
"conflicts": true
});
}).then(function (answer) {
deepEqual(answer.data,
shared.doc_myget3_cloned,
"Get document which have an attachment (winner)");
}).fail(unexpectedError).always(start);
});
// test("Remove", function () { // test("Remove", function () {
......
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