Commit 0bce7aa0 authored by Vincent Bechu's avatar Vincent Bechu

[cloudoostorage] add test on failed conversion

parent 81600fca
/*jslint nomen: true*/
/*global jIO, RSVP, Blob, Uint8Array, DOMParser*/
(function (jIO, Uint8Array, Blob, RSVP, DOMParser) {
/*global jIO, RSVP, Blob, Uint8Array, DOMParser, XMLSerializer*/
(function (jIO, Uint8Array, Blob, RSVP, DOMParser, XMLSerializer) {
"use strict";
var content_type_dict = {
"application/x-asc-text": "docy",
"application/x-asc-presentation": "",
"application/x-asc-spreadsheet": ""
};
},
parser = new DOMParser(),
serializer = new XMLSerializer();
function newXml() {
return parser.parseFromString(
'<?xml version="1.0" encoding="UTF-8"?><methodCall>' +
'<methodName>convertFile</methodName><params>' +
'<param><value><string></string></value></param>' +
'<param><value><string></string></value></param>' +
'<param><value><string></string></value></param></params></methodCall>',
'text/xml'
);
}
function b64toBlob(b64Data, contentType, sliceSize) {
contentType = contentType || '';
......@@ -47,28 +60,27 @@
.push(function (result) {
// WIP: use something cleaner
var file = result.target.result.split('base64,')[1],
xml = '<?xml version="1.0" encoding="UTF-8"?><methodCall>' +
'<methodName>convertFile</methodName><params>' +
'<param><value><string>' + file + '</string></value></param>' +
'<param><value><string>' + from + '</string></value></param>' +
'<param><value><string>' + to +
'</string></value></param></params></methodCall>';
xml = newXml(),
string_list = xml.getElementsByTagName('string');
string_list[0].textContent = file;
string_list[1].textContent = from;
string_list[2].textContent = to;
return jIO.util.ajax({
type: 'POST',
url: storage._url,
data: xml
data: serializer.serializeToString(xml)
});
})
.push(function (result) {
var data = (new DOMParser().parseFromString(
var data = parser.parseFromString(
result.target.responseText,
"application/xml"
)),
content = data.getElementsByTagName('string')[0].textContent;
if (content !== undefined) {
return b64toBlob(content, to);
),
content = data.getElementsByTagName('string');
if (content.length > 0) {
return b64toBlob(content[0].textContent, to);
}
throw new jIO.util.jIOError('conversion failed', 400);
throw new jIO.util.jIOError('conversion failed', 404);
});
}
......@@ -275,4 +287,4 @@
jIO.addStorage('cloudoo', CloudooStorage);
}(jIO, Uint8Array, Blob, RSVP, DOMParser));
}(jIO, Uint8Array, Blob, RSVP, DOMParser, XMLSerializer));
......@@ -381,7 +381,7 @@
test("getAttachment convert from docy to docx", function () {
stop();
expect(10);
expect(12);
var blob = new Blob(["documentauformatdocy"]),
server = this.server,
......@@ -434,6 +434,8 @@
this.jio.getAttachment("bar", "data?docx")
.then(function (result) {
equal(server.requests.length, 1);
equal(server.requests[0].method, "POST");
equal(server.requests[0].url, cloudoo_url);
equal(
server.requests[0].requestBody,
'<?xml version="1.0" encoding="UTF-8"?><methodCall>' +
......@@ -452,6 +454,59 @@
start();
});
});
test("getAttachment convert from docy to docx failed", function () {
stop();
expect(4);
var blob = new Blob(["documentauformatdocy"]);
this.server.respondWith("POST", cloudoo_url, [200, {
"Content-Type": "text/xml"
}, '<?xml version="1.0" encoding="UTF-8"?>']);
Storage200.prototype.getAttachment = function (id, name) {
equal(id, "bar", "getAttachment 200 called");
if (name === "data?docx") {
throw new jIO.util.jIOError("can't find", 404);
}
return blob;
};
Storage200.prototype.get = function (id) {
if (id === "cloudoo/bar/data") {
throw new jIO.util.jIOError("can't find", 404);
}
if (id === "bar") {
return {content_type: "application/x-asc-text"};
}
equal(id, "", "get 200 called");
return {};
};
Storage200.prototype.put = function (id, doc) {
equal(id, "cloudoo/bar/data", "put 200 called");
deepEqual(doc, {
"attachment_id": "data",
"convert_dict": {
"docx": false
},
"doc_id": "bar",
"format": "docy",
"portal_type": "Conversion Info"
}, "put doc 200 called");
return id;
};
this.jio.getAttachment("bar", "data?docx")
.fail(function (error) {
equal(error.message, "conversion failed", "check conversion failed");
equal(error.status_code, 404, "check error status code");
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// CryptStorage.putAttachment
/////////////////////////////////////////////////////////////////
......
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