Commit 0cb19bd8 authored by Romain Courteaud's avatar Romain Courteaud

Memory storage: throw 404 if attachment is undefined

parent f8efbe05
......@@ -81,7 +81,14 @@
MemoryStorage.prototype.getAttachment = function (param) {
try {
return {data: this._database[param._id].attachments[param._attachment]};
var result = this._database[param._id].attachments[param._attachment];
if (result === undefined) {
throw new jIO.util.jIOError(
"Cannot find attachment: " + param._id + " , " + param._attachment,
404
);
}
return {data: result};
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError(
......
......@@ -273,6 +273,34 @@
});
});
test("get inexistent attachment from document with other attachments",
function () {
var id = "b";
stop();
expect(3);
this.jio.__storage._database[id] = {
"doc": JSON.stringify({}),
attachments: {"foo": "bar"}
};
this.jio.getAttachment({
"_id": id,
"_attachment": "inexistent"
})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find attachment: b , inexistent");
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("get attachment from document", function () {
var id = "putattmt1",
attachment = "putattmt2",
......
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