Commit 8ad93226 authored by Romain Courteaud's avatar Romain Courteaud

ERP5 storage: handle 404 status code

parent 299a0345
...@@ -38,17 +38,27 @@ ...@@ -38,17 +38,27 @@
return getSiteDocument(storage) return getSiteDocument(storage)
.push(function (site_hal) { .push(function (site_hal) {
// XXX need to get modified metadata // XXX need to get modified metadata
return jIO.util.ajax({ return new RSVP.Queue()
"type": "GET", .push(function () {
"url": UriTemplate.parse(site_hal._links.traverse.href) return jIO.util.ajax({
.expand({ "type": "GET",
relative_url: id, "url": UriTemplate.parse(site_hal._links.traverse.href)
view: options._view .expand({
}), relative_url: id,
"xhrFields": { view: options._view
withCredentials: true }),
} "xhrFields": {
}); withCredentials: true
}
});
})
.push(undefined, function (error) {
if ((error.target !== undefined) &&
(error.target.status === 404)) {
throw new jIO.util.jIOError("Cannot find document: " + id, 404);
}
throw error;
});
}); });
} }
......
...@@ -64,6 +64,35 @@ ...@@ -64,6 +64,35 @@
} }
}); });
test("get inexistent document", function () {
var id = "person_module/20150119_azerty",
traverse_url = domain + "?mode=traverse&relative_url=" +
encodeURIComponent(id);
this.server.respondWith("GET", domain, [200, {
"Content-Type": "application/hal+json"
}, root_hateoas]);
this.server.respondWith("GET", traverse_url, [404, {
"Content-Type": "text/html"
}, ""]);
stop();
expect(3);
this.jio.get(id)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " + id);
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("get ERP5 document", function () { test("get ERP5 document", function () {
var id = "person_module/20150119_azerty", var id = "person_module/20150119_azerty",
traverse_url = domain + "?mode=traverse&relative_url=" + traverse_url = domain + "?mode=traverse&relative_url=" +
...@@ -136,6 +165,35 @@ ...@@ -136,6 +165,35 @@
} }
}); });
test("allAttachments on inexistent document", function () {
var id = "person_module/20150119_azerty",
traverse_url = domain + "?mode=traverse&relative_url=" +
encodeURIComponent(id);
this.server.respondWith("GET", domain, [200, {
"Content-Type": "application/hal+json"
}, root_hateoas]);
this.server.respondWith("GET", traverse_url, [404, {
"Content-Type": "text/html"
}, ""]);
stop();
expect(3);
this.jio.allAttachments(id)
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " + id);
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("allAttachments ERP5 document", function () { test("allAttachments ERP5 document", function () {
var id = "person_module/20150119_azerty", var id = "person_module/20150119_azerty",
traverse_url = domain + "?mode=traverse&relative_url=" + traverse_url = domain + "?mode=traverse&relative_url=" +
...@@ -322,6 +380,35 @@ ...@@ -322,6 +380,35 @@
}); });
}); });
test("getAttachment: view on inexistent document", function () {
var id = "person_module/1",
traverse_url = domain + "?mode=traverse&relative_url=" +
encodeURIComponent(id) + "&view=foo_view";
this.server.respondWith("GET", domain, [200, {
"Content-Type": "application/hal+json"
}, root_hateoas]);
this.server.respondWith("GET", traverse_url, [404, {
"Content-Type": "text/html"
}, ""]);
stop();
expect(3);
this.jio.getAttachment(id, "view")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " + id);
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("getAttachment: view uses default form", function () { test("getAttachment: view uses default form", function () {
var id = "person_module/1", var id = "person_module/1",
traverse_url = domain + "?mode=traverse&relative_url=" + traverse_url = domain + "?mode=traverse&relative_url=" +
...@@ -379,6 +466,35 @@ ...@@ -379,6 +466,35 @@
}); });
}); });
test("getAttachment: links on inexistent document", function () {
var id = "person_module/1",
traverse_url = domain + "?mode=traverse&relative_url=" +
encodeURIComponent(id);
this.server.respondWith("GET", domain, [200, {
"Content-Type": "application/hal+json"
}, root_hateoas]);
this.server.respondWith("GET", traverse_url, [404, {
"Content-Type": "text/html"
}, ""]);
stop();
expect(3);
this.jio.getAttachment(id, "links")
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document: " + id);
equal(error.status_code, 404);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("getAttachment: links uses no form", function () { test("getAttachment: links uses no form", function () {
var id = "person_module/1", var id = "person_module/1",
traverse_url = domain + "?mode=traverse&relative_url=" + traverse_url = domain + "?mode=traverse&relative_url=" +
......
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