Commit b5680a20 authored by Romain Courteaud's avatar Romain Courteaud

fix dropbox onnode

parent 13a2e799
...@@ -709,6 +709,8 @@ ...@@ -709,6 +709,8 @@
this.server.autoRespond = true; this.server.autoRespond = true;
this.server.autoRespondAfter = 5; this.server.autoRespondAfter = 5;
this.spy_ajax = sinon.spy(jIO.util, "ajax");
this.jio = jIO.createJIO({ this.jio = jIO.createJIO({
type: "dropbox", type: "dropbox",
access_token: token access_token: token
...@@ -717,6 +719,8 @@ ...@@ -717,6 +719,8 @@
teardown: function () { teardown: function () {
this.server.restore(); this.server.restore();
delete this.server; delete this.server;
this.spy_ajax.restore();
delete this.spy_ajax;
} }
}); });
...@@ -789,14 +793,15 @@ ...@@ -789,14 +793,15 @@
test("putAttachment document", function () { test("putAttachment document", function () {
var blob = new Blob(["foo"], {"type": "xapplication/foo"}), var blob = new Blob(["foo"], {"type": "xapplication/foo"}),
url_put_att = "https://content.dropboxapi.com/2/files/upload", url_put_att = "https://content.dropboxapi.com/2/files/upload",
server = this.server; server = this.server,
context = this;
this.server.respondWith("POST", url_put_att, [204, { this.server.respondWith("POST", url_put_att, [204, {
"Content-Type": "text/xml" "Content-Type": "text/xml"
}, ""]); }, ""]);
stop(); stop();
expect(7); expect(11);
this.jio.putAttachment( this.jio.putAttachment(
"/putAttachment1/", "/putAttachment1/",
...@@ -804,20 +809,26 @@ ...@@ -804,20 +809,26 @@
blob blob
) )
.then(function () { .then(function () {
ok(context.spy_ajax.calledOnce, "ajax count " +
context.spy_ajax.callCount);
equal(context.spy_ajax.firstCall.args[0].type, "POST");
equal(context.spy_ajax.firstCall.args[0].url, url_put_att);
deepEqual(context.spy_ajax.firstCall.args[0].xhrFields, undefined);
deepEqual(context.spy_ajax.firstCall.args[0].headers, {
"Authorization": "Bearer sample_token",
"Content-Type": "application/octet-stream",
"Dropbox-API-Arg": '{"path":"/putAttachment1/attachment1",' +
'"mode":"overwrite",' +
'"autorename":false,"mute":false}'
});
equal(context.spy_ajax.firstCall.args[0].data, blob);
equal(server.requests.length, 1); equal(server.requests.length, 1);
equal(server.requests[0].method, "POST"); equal(server.requests[0].method, "POST");
equal(server.requests[0].url, url_put_att); equal(server.requests[0].url, url_put_att);
equal(server.requests[0].status, 204); equal(server.requests[0].status, 204);
equal(server.requests[0].responseText, ""); equal(server.requests[0].responseText, "");
deepEqual(server.requests[0].requestHeaders, {
"Authorization": "Bearer sample_token",
"Content-Type": "application/octet-stream;charset=utf-8",
"Dropbox-API-Arg": '{"path":"/putAttachment1/attachment1",' +
'"mode":"overwrite",' +
'"autorename":false,"mute":false}'
});
equal(server.requests[0].requestBody, blob);
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
......
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