Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

support basePath, test basePath and timeout

  • Loading branch information...
commit 80669687d4f081721cf32565c07e46c4b40f5019 1 parent 95741b5
@marianoguerra authored
Showing with 53 additions and 0 deletions.
  1. +4 −0 src/intercal.js
  2. +49 −0 test/test.js
View
4 src/intercal.js
@@ -289,6 +289,10 @@
function request(path, body, method, options) {
var opts = {};
+ if (options.basePath) {
+ path = intercal.path.join(options.basePath, path);
+ }
+
if (body) {
if (options.contentType === "application/json") {
opts.data = JSON.stringify(body);
View
49 test/test.js
@@ -750,6 +750,55 @@
{"contentType": "text/plain", "data": "asd", "type": "POST"});
});
+ test("requester adds timeout and basePath if defined in config", function () {
+ var request, data = {"name": "pedro"},
+ dataStr = JSON.stringify(data),
+ ic = $.intercal({
+ "resourceConfig": {
+ "contentType": "application/json",
+ "timeout": 1000,
+ "basePath": "/base/"
+ },
+ "resource": {
+ "user": {
+ "path": {
+ "get delete": "/api/user/{id}",
+ "post put": "/api/user"
+ }
+ },
+ "session": {
+ "path": "/api/session",
+ "config": {
+ "contentType": "application/xml"
+ }
+ }
+
+ }
+ });
+
+ checkAjaxRequest(ic, ic.resource.user.create, "/base/api/user", data,
+ "POST", {}, {
+ "contentType": "application/json",
+ "data": dataStr,
+ "type": "POST",
+ "timeout": 1000
+ });
+ checkAjaxRequest(ic, ic.resource.user.create, "/base/api/user", "asd",
+ "POST", {"contentType": "application/xml"}, {
+ "contentType": "application/xml",
+ "data": "asd",
+ "type": "POST",
+ "timeout": 1000
+ });
+ checkAjaxRequest(ic, ic.resource.session.update, "/base/api/session",
+ "asd", "POST", {"timeout": 2000}, {
+ "contentType": "application/xml",
+ "data": "asd",
+ "type": "PUT",
+ "timeout": 2000
+ });
+ });
+
test("requester interpolates path", function () {
var request, data = {"name": "pedro"},
dataStr = JSON.stringify(data),
Please sign in to comment.
Something went wrong with that request. Please try again.