eh-api-client
Advanced tools
Comparing version 0.14.0 to 0.15.0
31
index.js
@@ -53,2 +53,4 @@ var | ||
this.apiURL = apiURL; | ||
this.requestId = null; | ||
this.sessionId = null; | ||
this._factory = null; | ||
@@ -64,2 +66,10 @@ }; | ||
Client.prototype.setRequestId = function(requestId) { | ||
this.requestId = requestId; | ||
}; | ||
Client.prototype.setSessionId = function(sessionId) { | ||
this.sessionId = sessionId; | ||
}; | ||
Client.prototype.request = function(method, options, body, cb) { | ||
@@ -100,2 +110,8 @@ var deferred = Q.defer(); | ||
} | ||
if(this.requestId) { | ||
reqParams.headers["x-request-id"] = this.requestId; | ||
} | ||
if(this.sessionId) { | ||
reqParams.headers["x-session-id"] = this.sessionId; | ||
} | ||
if(options.filter) { | ||
@@ -277,2 +293,17 @@ reqParams.qs.filter = (JSON.stringify(options.filter)); | ||
/** | ||
* @param {Number} userId | ||
* @param {String} app | ||
*/ | ||
Factory.prototype.getClientByContext = function(context) { | ||
var client = new Client(this.apiURL, { | ||
internalAuth: context.userId + ":" + context.remoteAppCode | ||
}); | ||
client.setRequestId(context.requestId); | ||
client.setSessionId(context.sessionId); | ||
client._factory = this; | ||
return client; | ||
}; | ||
module.exports = Factory; |
{ | ||
"name": "eh-api-client", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"description": "Node.js rest client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -49,2 +49,33 @@ var | ||
describe("Create client from context", function() { | ||
it("should create client from context", function() { | ||
var context = { | ||
userId: 1, | ||
remoteAppCode: "app", | ||
requestId: "request-id", | ||
sessionId: "session-id" | ||
}; | ||
var client = f.getClientByContext(context); | ||
client.requestId.should.equal(context.requestId); | ||
client.sessionId.should.equal(context.sessionId); | ||
client.internalAuth.should.equal(context.userId + ":" + context.remoteAppCode); | ||
}); | ||
}); | ||
describe("Send requestId/sessionId", function() { | ||
it("should set requestId and sessionId in header", function(done) { | ||
var client = f.getClient(); | ||
client.setRequestId("request-id"); | ||
client.setSessionId("session-id"); | ||
client.request("GET", { | ||
test: true, | ||
url: "/" | ||
}, function(err, params) { | ||
params.headers["x-request-id"].should.equal("request-id"); | ||
params.headers["x-session-id"].should.equal("session-id"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe("Internal Auth Client test", function() { | ||
@@ -67,39 +98,3 @@ var noteGlobalId = ehGuid.gen(); | ||
}); | ||
/* | ||
it("get notes list", function(done) { | ||
client.get("/notes/", function(err, data) { | ||
should.not.exists(err); | ||
data.should.be.an.instanceOf(Array); | ||
done(); | ||
}); | ||
}); | ||
it("create note", function(done) { | ||
client.patch("/notes/" + noteGlobalId, { | ||
title: "test note", | ||
parentId: "default" | ||
}, function(err) { | ||
should.not.exists(err); | ||
done(); | ||
}); | ||
}); | ||
it("get note", function(done) { | ||
client.get("/notes/" + noteGlobalId, function(err, data, res) { | ||
should.not.exists(err); | ||
res.should.type("object"); | ||
data.title.should.equal("test note"); | ||
data.globalId.should.equal(noteGlobalId); | ||
done(); | ||
}); | ||
}); | ||
it("get note(promise)", function(done) { | ||
client.get("/notes/" + noteGlobalId).then(function(data) { | ||
data.title.should.equal("test note"); | ||
data.globalId.should.equal(noteGlobalId); | ||
done(); | ||
}).done(); | ||
}); | ||
*/ | ||
it("should make correct filter request", function(done) { | ||
@@ -106,0 +101,0 @@ var filter = { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17554
637