Commit 19cff054 authored by Romain Courteaud's avatar Romain Courteaud

Add ERP5Storage tests

parent 205247b1
...@@ -10,10 +10,9 @@ ...@@ -10,10 +10,9 @@
// } // }
/*jslint nomen: true */ /*jslint nomen: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, /*global jIO, UriTemplate, FormData, RSVP, URI, Blob*/
Blob, btoa */
(function (jIO, UriTemplate, RSVP, URI, Blob) { (function (jIO, UriTemplate, FormData, RSVP, URI, Blob) {
"use strict"; "use strict";
function getSiteDocument(storage) { function getSiteDocument(storage) {
...@@ -75,8 +74,6 @@ ...@@ -75,8 +74,6 @@
result._id = param._id; result._id = param._id;
result.portal_type = result._links.type.name; result.portal_type = result._links.type.name;
result._attachments = attachments;
// Remove all ERP5 hateoas links / convert them into jIO ID // Remove all ERP5 hateoas links / convert them into jIO ID
for (key in result) { for (key in result) {
if (result.hasOwnProperty(key)) { if (result.hasOwnProperty(key)) {
...@@ -86,6 +83,8 @@ ...@@ -86,6 +83,8 @@
} }
} }
result._attachments = attachments;
return result; return result;
}); });
}; };
...@@ -105,19 +104,19 @@ ...@@ -105,19 +104,19 @@
// if Base_edit, do put URN // if Base_edit, do put URN
// if others, do post URN (ie, unique new attachment name) // if others, do post URN (ie, unique new attachment name)
// XXX Except this attachment name should be generated when // XXX Except this attachment name should be generated when
return new Blob( return {data: new Blob(
[JSON.stringify(result)], [JSON.stringify(result)],
{"type": 'application/hal+json'} {"type": 'application/hal+json'}
); )};
}); });
} }
if (action === "links") { if (action === "links") {
return getDocumentAndHateoas(this, param) return getDocumentAndHateoas(this, param)
.push(function (response) { .push(function (response) {
return new Blob( return {data: new Blob(
[JSON.stringify(JSON.parse(response.target.responseText))], [JSON.stringify(JSON.parse(response.target.responseText))],
{"type": 'application/hal+json'} {"type": 'application/hal+json'}
); )};
}); });
} }
if (action.indexOf(this._url) === 0) { if (action.indexOf(this._url) === 0) {
...@@ -134,20 +133,21 @@ ...@@ -134,20 +133,21 @@
.push(function (evt) { .push(function (evt) {
var result = JSON.parse(evt.target.responseText); var result = JSON.parse(evt.target.responseText);
result._id = param._id; result._id = param._id;
return new Blob( return {data: new Blob(
[JSON.stringify(result)], [JSON.stringify(result)],
{"type": evt.target.getResponseHeader("Content-Type")} {"type": evt.target.getResponseHeader("Content-Type")}
); )};
}); });
} }
throw new Error("ERP5: not support get attachment: " + action); throw new jIO.util.jIOError("ERP5: not support get attachment: " + action,
400);
}; };
ERP5Storage.prototype.putAttachment = function (metadata) { ERP5Storage.prototype.putAttachment = function (metadata) {
// Assert we use a callable on a document from the ERP5 site // Assert we use a callable on a document from the ERP5 site
if (metadata._attachment.indexOf(this._url) !== 0) { if (metadata._attachment.indexOf(this._url) !== 0) {
throw new Error("Can not store outside ERP5: " + throw new jIO.util.jIOError("Can not store outside ERP5: " +
metadata._attachment); metadata._attachment, 400);
} }
return new RSVP.Queue() return new RSVP.Queue()
...@@ -217,7 +217,6 @@ ...@@ -217,7 +217,6 @@
delete item._links; delete item._links;
result.push({ result.push({
id: uri.segment(2), id: uri.segment(2),
doc: {},
value: item value: item
}); });
} }
...@@ -227,4 +226,4 @@ ...@@ -227,4 +226,4 @@
jIO.addStorage("erp5", ERP5Storage); jIO.addStorage("erp5", ERP5Storage);
}(jIO, UriTemplate, RSVP, URI, Blob)); }(jIO, UriTemplate, FormData, RSVP, URI, Blob));
This diff is collapsed.
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
<script src="jio.storage/davstorage.tests.js"></script> <script src="jio.storage/davstorage.tests.js"></script>
<script src="jio.storage/drivetojiomapping.tests.js"></script> <script src="jio.storage/drivetojiomapping.tests.js"></script>
<script src="jio.storage/unionstorage.tests.js"></script> <script src="jio.storage/unionstorage.tests.js"></script>
<script src="jio.storage/erp5storage.tests.js"></script>
<!--script src="jio.storage/indexeddbstorage.tests.js"></script--> <!--script src="jio.storage/indexeddbstorage.tests.js"></script-->
<!--script src="jio.storage/indexstorage.tests.js"></script--> <!--script src="jio.storage/indexstorage.tests.js"></script-->
......
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