Commit aef35ca4 authored by Romain Courteaud's avatar Romain Courteaud

[linshare] test getAttachment

parent 8f14cbdc
......@@ -65,6 +65,14 @@
return jIO.util.ajax(options);
})
.push(function (event) {
if (download === true) {
return (
event.target.response ||
// sinon does not fill the response attribute
new Blob([event.target.responseText], {type: 'text/plain'})
);
}
return (
event.target.response ||
// sinon does not fill the response attribute
......
......@@ -821,7 +821,6 @@
})
.fail(function (error) {
console.warn(error);
ok(false, error);
})
.always(function () {
......@@ -978,7 +977,6 @@
}
});
test("forbidden attachment", function () {
var server = this.server;
......@@ -1145,27 +1143,160 @@
});
/////////////////////////////////////////////////////////////////
// DropboxStorage.getAttachment
// LinshareStorage.getAttachment
/////////////////////////////////////////////////////////////////
module("LinshareStorage.getAttachment");
module("LinshareStorage.getAttachment", {
setup: function () {
this.server = sinon.fakeServer.create();
this.server.autoRespond = true;
this.server.autoRespondAfter = 5;
this.jio = jIO.createJIO({
type: "linshare",
url: domain
});
},
teardown: function () {
this.server.restore();
delete this.server;
}
});
test("forbidden attachment", function () {
var server = this.server;
test("getAttachment retrieve content", function () {
stop();
expect(1);
var jio = jIO.createJIO({
type: "linshare"
}),
doc_id;
jio.post({})
.then(function (id) {
doc_id = id;
return jio.putAttachment(id, "data", new Blob(['tralalaal']));
expect(4);
this.jio.getAttachment('foo', 'bar')
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "attachment name bar is forbidden in linshare");
equal(error.status_code, 400);
equal(server.requests.length, 0);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("non existing document", function () {
var search_url = domain + "/linshare/webservice/rest/user/v2/documents/",
search_result = JSON.stringify([
{
uuid: 'uuid1',
name: 'foo1',
modificationDate: '2'
}, {
uuid: 'uuid2',
name: 'foo2',
modificationDate: '1'
}
]),
server = this.server;
this.server.respondWith("GET", search_url, [200, {
"Content-Type": "application/json"
}, search_result]);
stop();
expect(9);
this.jio.getAttachment('foo', 'enclosure')
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Can't find document with id : foo");
equal(error.status_code, 404);
equal(server.requests.length, 1);
equal(server.requests[0].method, "GET");
equal(server.requests[0].url, search_url);
equal(server.requests[0].requestBody, undefined);
equal(server.requests[0].withCredentials, true);
deepEqual(server.requests[0].requestHeaders, {
"Accept": "application/json"
});
})
.then(function () {
return jio.getAttachment(doc_id, "data");
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("retrieve a document", function () {
var search_url = domain + "/linshare/webservice/rest/user/v2/documents/",
search_result = JSON.stringify([
{
uuid: 'uuid1',
name: 'foo1',
modificationDate: '2'
}, {
uuid: 'uuid2',
name: 'foo2',
modificationDate: '1'
}, {
uuid: 'uuid4',
name: 'foo',
modificationDate: '2',
}, {
uuid: 'uuid5',
name: 'foo',
modificationDate: '1',
}, {
uuid: 'uuid3',
name: 'foo',
modificationDate: '3',
metaData: JSON.stringify({
title: 'foouuid3'
})
}
]),
download_url =
domain + "/linshare/webservice/rest/user/v2/documents/uuid3/download",
server = this.server;
this.server.respondWith("GET", search_url, [200, {
"Content-Type": "application/json"
}, search_result]);
this.server.respondWith("GET", download_url, [200, {
"Content-Type": "text/plain"
}, "foo\nbaré"]);
stop();
expect(14);
this.jio.getAttachment('foo', 'enclosure')
.then(function (result) {
equal(server.requests.length, 2);
equal(server.requests[0].method, "GET");
equal(server.requests[0].url, search_url);
equal(server.requests[0].requestBody, undefined);
equal(server.requests[0].withCredentials, true);
deepEqual(server.requests[0].requestHeaders, {
"Accept": "application/json"
});
equal(server.requests[1].method, "GET");
equal(server.requests[1].url, download_url);
equal(server.requests[1].requestBody, undefined);
equal(server.requests[1].withCredentials, true);
deepEqual(server.requests[1].requestHeaders, {});
ok(result instanceof Blob, "Data is Blob");
deepEqual(result.type, "text/plain", "Check mimetype");
return jIO.util.readBlobAsText(result);
})
.then(function (result) {
deepEqual(new Blob(['tralalaal']), result, "Check Blob");
var expected = "foo\nbaré";
equal(result.target.result, expected, "Attachment correctly fetched");
})
.fail(function (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