Commit 14831f19 authored by lucas.parsy's avatar lucas.parsy

added allAttachments method to gdriveStorage with tests.

corrected bug in get method returning a string instead of an object.
parent 1d0a1be4
......@@ -212,7 +212,7 @@
(attach ? new Blob([evt.target.responseText],
{"type" :
evt.target.responseHeaders["Content-Type"]}) :
evt.target.responseText);
JSON.parse(evt.target.responseText));
}, function (error) {handleError(error, id); });
}
......@@ -225,6 +225,21 @@
return getData(id, true, this._access_token);
};
GdriveStorage.prototype.allAttachments = function (id) {
var token = this._access_token;
return new RSVP.Queue()
.push(function () {
return getData(id, false, token);
})
.push(function (data) {
if (data.mimeType === "application/vnd.google-apps.folder") {
return {};
}
return {"enclosure": {}};
});
};
jIO.addStorage('gdrive', GdriveStorage);
}(jIO, Blob, RSVP, UriTemplate, JSON));
......@@ -292,7 +292,10 @@
this.jio.get("sampleId")
.then(function (result) {
deepEqual(result, body, "Check document");
deepEqual(result,
{"id": "sampleId",
"mimeType": "application/vnd.google-apps.folder",
"title": "folder1"}, "Check document");
})
.fail(function (error) {
ok(false, error);
......@@ -608,4 +611,80 @@
tester("getAttachment", true);
});
/////////////////////////////////////////////////////////////////
// Google Drive Storage.allAttachments
/////////////////////////////////////////////////////////////////
module("Google Drive Storage.allAttachments", {
setup: function () {
this.server = sinon.fakeServer.create();
this.server.autoRespond = true;
this.server.autoRespondAfter = 5;
this.jio = jIO.createJIO({
type: "gdrive",
access_token: token
});
},
teardown: function () {
this.server.restore();
delete this.server;
}
});
test("allAttachments on file", function () {
var url = domain + "/drive/v2/files/sampleId?alt=",
body = '{"id": "sampleId", "mimeType":' +
'"text/xml", "title": "folder1"}';
this.server.respondWith("GET", url, [200, {
"Content-Type": "text/xml"
}, body
]);
stop();
expect(1);
this.jio.allAttachments("sampleId")
.then(function (result) {
deepEqual(result, {enclosure: {}}, "enclosure on file");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("allAttachments on directory", function () {
var url = domain + "/drive/v2/files/sampleId?alt=",
body = '{"id": "sampleId", "mimeType":' +
'"application/vnd.google-apps.folder", "title": "folder1"}';
this.server.respondWith("GET", url, [200, {
"Content-Type": "text/xml"
}, body
]);
stop();
expect(1);
this.jio.allAttachments("sampleId")
.then(function (result) {
deepEqual(result, {}, "empty result on directory");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("get inexistent attachment", function () {
var tester = error404Tester.bind(this);
tester("allAttachments");
});
}(jIO, QUnit, Blob, sinon));
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