Commit eaa2151a authored by Romain Courteaud's avatar Romain Courteaud

wip

parent 62b0d562
......@@ -56,7 +56,10 @@
}
return result
.push(function (evt) {
evt.target.response = new Blob([evt.target.response]);
evt.target.response = new Blob(
[evt.target.response || evt.target.responseText],
{type: evt.target.getResponseHeader('Content-Type')}
);
return evt;
});
}
......@@ -65,13 +68,13 @@
jIO.util.ajax = function ajax(param) {
var result,
need_convertion = (param.dataType === 'blob');
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param = Object.assign({}, param);
if (need_convertion) {
param.dataType = 'arraybuffer';
}
if (param.data instanceof Blob) {
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param = Object.assign({}, param);
// Blob is not supported by xhr2, so convert to ArrayBuffer instead
result = new RSVP.Queue()
.push(function () {
......@@ -82,9 +85,6 @@
return originalAjax(param);
});
} else if (param.data instanceof FormData) {
// Copy the param dict document (no need for deep copy) to
// allow tests to check them
param = Object.assign({}, param);
// Implement minimal FormData for erp5storage
if (!param.hasOwnProperty('headers')) {
param.headers = {};
......
......@@ -1003,8 +1003,12 @@
type: "dropbox",
access_token: token
});
this.spy_ajax = sinon.spy(jIO.util, "ajax");
},
teardown: function () {
this.spy_ajax.restore();
delete this.spy_ajax;
this.server.restore();
delete this.server;
}
......@@ -1075,7 +1079,7 @@
test("getAttachment document", function () {
var url = "https://content.dropboxapi.com/2/files/download",
server = this.server;
context = this;
this.server.respondWith("POST", url, [200, {
"Content-Type": "text/xplain"
}, "foo\nbaré"]);
......@@ -1088,20 +1092,20 @@
"attachment1"
)
.then(function (result) {
equal(server.requests.length, 1);
equal(server.requests[0].method, "POST");
equal(server.requests[0].url, url);
equal(server.requests[0].status, 200);
equal(server.requests[0].requestBody, undefined);
equal(server.requests[0].responseText, "foo\nbaré");
deepEqual(server.requests[0].requestHeaders, {
equal(context.spy_ajax.callCount, 1);
equal(context.spy_ajax.firstCall.args[0].type, "POST");
equal(context.spy_ajax.firstCall.args[0].url, url);
equal(context.spy_ajax.firstCall.args[0].data, undefined);
equal(context.spy_ajax.firstCall.args[0].dataType, 'blob');
deepEqual(context.spy_ajax.firstCall.args[0].xhrFields, undefined);
deepEqual(context.spy_ajax.firstCall.args[0].headers, {
"Authorization": "Bearer sample_token",
"Content-Type": "text/plain;charset=utf-8",
"Dropbox-API-Arg": '{"path":"/getAttachment1/attachment1"}'
});
ok(result instanceof Blob, "Data is Blob");
deepEqual(result.type, "text/xplain", "Check mimetype");
return jIO.util.readBlobAsText(result);
})
.then(function (result) {
......
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