|
|
@@ -2,10 +2,10 @@ sinon = require('sinon')
|
|
|
chai = require('chai')
|
|
|
should = chai.should()
|
|
|
expect = chai.expect
|
|
|
-modulePath = "../../../../app/js/Features/Compile/ClsiRequestManager.js"
|
|
|
+modulePath = "../../../../app/js/Features/Compile/ClsiCookieManager.js"
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
realRequst = require("request")
|
|
|
-describe "ClsiRequestManager", ->
|
|
|
+describe "ClsiCookieManager", ->
|
|
|
beforeEach ->
|
|
|
@redisMulti =
|
|
|
set:sinon.stub()
|
|
|
@@ -18,7 +18,7 @@ describe "ClsiRequestManager", ->
|
|
|
get: sinon.stub()
|
|
|
cookie:realRequst.cookie
|
|
|
jar: realRequst.jar
|
|
|
- @ClsiRequestManager = SandboxedModule.require modulePath, requires:
|
|
|
+ @ClsiCookieManager = SandboxedModule.require modulePath, requires:
|
|
|
"redis-sharelatex" :
|
|
|
createClient: =>
|
|
|
auth:->
|
|
|
@@ -39,33 +39,33 @@ describe "ClsiRequestManager", ->
|
|
|
|
|
|
it "should call get for the key", (done)->
|
|
|
@redisMulti.exec.callsArgWith(0, null, ["clsi-7"])
|
|
|
- @ClsiRequestManager._getServerId @project_id, (err, serverId)=>
|
|
|
+ @ClsiCookieManager._getServerId @project_id, (err, serverId)=>
|
|
|
@redisMulti.get.calledWith("clsiserver:#{@project_id}").should.equal true
|
|
|
serverId.should.equal "clsi-7"
|
|
|
done()
|
|
|
|
|
|
it "should expire the key", (done)->
|
|
|
@redisMulti.exec.callsArgWith(0, null, ["clsi-7"])
|
|
|
- @ClsiRequestManager._getServerId @project_id, (err, serverId)=>
|
|
|
+ @ClsiCookieManager._getServerId @project_id, (err, serverId)=>
|
|
|
@redisMulti.expire.calledWith("clsiserver:#{@project_id}", 60 * 60 * 24 * 7).should.equal true
|
|
|
done()
|
|
|
|
|
|
- it "should _getServerIdViaRequest if no key is found", (done)->
|
|
|
- @ClsiRequestManager._getServerIdViaRequest = sinon.stub().callsArgWith(1)
|
|
|
+ it "should _populateServerIdViaRequest if no key is found", (done)->
|
|
|
+ @ClsiCookieManager._populateServerIdViaRequest = sinon.stub().callsArgWith(1)
|
|
|
@redisMulti.exec.callsArgWith(0, null, [])
|
|
|
- @ClsiRequestManager._getServerId @project_id, (err, serverId)=>
|
|
|
- @ClsiRequestManager._getServerIdViaRequest.calledWith(@project_id).should.equal true
|
|
|
+ @ClsiCookieManager._getServerId @project_id, (err, serverId)=>
|
|
|
+ @ClsiCookieManager._populateServerIdViaRequest.calledWith(@project_id).should.equal true
|
|
|
done()
|
|
|
|
|
|
|
|
|
- describe "_getServerIdViaRequest", ->
|
|
|
+ describe "_populateServerIdViaRequest", ->
|
|
|
|
|
|
it "should make a request to the clsi", (done)->
|
|
|
response = "some data"
|
|
|
@request.get.callsArgWith(1, null, response)
|
|
|
- @ClsiRequestManager.setServerId = sinon.stub().callsArgWith(2)
|
|
|
- @ClsiRequestManager._getServerIdViaRequest @project_id, (err, serverId)=>
|
|
|
- args = @ClsiRequestManager.setServerId.args[0]
|
|
|
+ @ClsiCookieManager.setServerId = sinon.stub().callsArgWith(2)
|
|
|
+ @ClsiCookieManager._populateServerIdViaRequest @project_id, (err, serverId)=>
|
|
|
+ args = @ClsiCookieManager.setServerId.args[0]
|
|
|
args[0].should.equal @project_id
|
|
|
args[1].should.deep.equal response
|
|
|
done()
|
|
|
@@ -73,10 +73,10 @@ describe "ClsiRequestManager", ->
|
|
|
describe "setServerId", ->
|
|
|
|
|
|
it "should set the server id with a ttl", (done)->
|
|
|
- @ClsiRequestManager._parseServerIdFromResponse = sinon.stub().returns("clsi-8")
|
|
|
+ @ClsiCookieManager._parseServerIdFromResponse = sinon.stub().returns("clsi-8")
|
|
|
response = "dsadsakj"
|
|
|
@redisMulti.exec.callsArgWith(0)
|
|
|
- @ClsiRequestManager.setServerId @project_id, response, (err)=>
|
|
|
+ @ClsiCookieManager.setServerId @project_id, response, (err)=>
|
|
|
@redisMulti.set.calledWith("clsiserver:#{@project_id}", "clsi-8").should.equal true
|
|
|
@redisMulti.expire.calledWith("clsiserver:#{@project_id}", 60 * 60 * 24 * 7).should.equal true
|
|
|
done()
|
|
|
@@ -85,23 +85,14 @@ describe "ClsiRequestManager", ->
|
|
|
describe "getCookieJar", ->
|
|
|
|
|
|
it "should return a jar with the cookie set populated from redis", (done)->
|
|
|
- @ClsiRequestManager._getServerId = sinon.stub().callsArgWith(1, null, "clsi-11")
|
|
|
+ @ClsiCookieManager._getServerId = sinon.stub().callsArgWith(1, null, "clsi-11")
|
|
|
opts = {}
|
|
|
- @ClsiRequestManager.getCookieJar @project_id, opts, (err, jar)->
|
|
|
+ @ClsiCookieManager.getCookieJar @project_id, (err, jar)->
|
|
|
jar._jar.store.idx["clsi.example.com"]["/"].clsiserver.key.should.equal "clsiserver"
|
|
|
jar._jar.store.idx["clsi.example.com"]["/"].clsiserver.value.should.equal "clsi-11"
|
|
|
done()
|
|
|
|
|
|
|
|
|
- # describe "_parseServerIdFromResponse", ->
|
|
|
- # it "take the cookie from the response", (done)->
|
|
|
-
|
|
|
- # a.should.equal
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
|