|
@@ -7,6 +7,11 @@ SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "ClsiManager", ->
|
|
describe "ClsiManager", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
|
|
+ @jar = {cookie:"stuff"}
|
|
|
|
|
+ @ClsiCookieManager =
|
|
|
|
|
+ getCookieJar: sinon.stub().callsArgWith(1, null, @jar)
|
|
|
|
|
+ setServerId: sinon.stub().callsArgWith(2)
|
|
|
|
|
+ _getServerId:sinon.stub()
|
|
|
@ClsiManager = SandboxedModule.require modulePath, requires:
|
|
@ClsiManager = SandboxedModule.require modulePath, requires:
|
|
|
"settings-sharelatex": @settings =
|
|
"settings-sharelatex": @settings =
|
|
|
apis:
|
|
apis:
|
|
@@ -19,14 +24,16 @@ describe "ClsiManager", ->
|
|
|
url: "https://clsipremium.example.com"
|
|
url: "https://clsipremium.example.com"
|
|
|
"../../models/Project": Project: @Project = {}
|
|
"../../models/Project": Project: @Project = {}
|
|
|
"../Project/ProjectEntityHandler": @ProjectEntityHandler = {}
|
|
"../Project/ProjectEntityHandler": @ProjectEntityHandler = {}
|
|
|
|
|
+ "./ClsiCookieManager": @ClsiCookieManager
|
|
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() }
|
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() }
|
|
|
- "request": @request = {}
|
|
|
|
|
|
|
+ "request": @request = sinon.stub()
|
|
|
@project_id = "project-id"
|
|
@project_id = "project-id"
|
|
|
@callback = sinon.stub()
|
|
@callback = sinon.stub()
|
|
|
|
|
|
|
|
describe "sendRequest", ->
|
|
describe "sendRequest", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@ClsiManager._buildRequest = sinon.stub().callsArgWith(2, null, @request = "mock-request")
|
|
@ClsiManager._buildRequest = sinon.stub().callsArgWith(2, null, @request = "mock-request")
|
|
|
|
|
+ @ClsiCookieManager._getServerId.callsArgWith(1, null, "clsi3")
|
|
|
|
|
|
|
|
describe "with a successful compile", ->
|
|
describe "with a successful compile", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
@@ -80,15 +87,15 @@ describe "ClsiManager", ->
|
|
|
|
|
|
|
|
describe "deleteAuxFiles", ->
|
|
describe "deleteAuxFiles", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @request.del = sinon.stub().callsArg(1)
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest = sinon.stub().callsArg(2)
|
|
|
|
|
|
|
|
describe "with the standard compileGroup", ->
|
|
describe "with the standard compileGroup", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@ClsiManager.deleteAuxFiles @project_id, {compileGroup: "standard"}, @callback
|
|
@ClsiManager.deleteAuxFiles @project_id, {compileGroup: "standard"}, @callback
|
|
|
|
|
|
|
|
it "should call the delete method in the standard CLSI", ->
|
|
it "should call the delete method in the standard CLSI", ->
|
|
|
- @request.del
|
|
|
|
|
- .calledWith("#{@settings.apis.clsi.url}/project/#{@project_id}")
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest
|
|
|
|
|
+ .calledWith(@project_id, { method:"DELETE", url:"#{@settings.apis.clsi.url}/project/#{@project_id}"})
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
it "should call the callback", ->
|
|
@@ -99,8 +106,8 @@ describe "ClsiManager", ->
|
|
|
@ClsiManager.deleteAuxFiles @project_id, {compileGroup: "priority"}, @callback
|
|
@ClsiManager.deleteAuxFiles @project_id, {compileGroup: "priority"}, @callback
|
|
|
|
|
|
|
|
it "should call the delete method in the CLSI", ->
|
|
it "should call the delete method in the CLSI", ->
|
|
|
- @request.del
|
|
|
|
|
- .calledWith("#{@settings.apis.clsi_priority.url}/project/#{@project_id}")
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest
|
|
|
|
|
+ .calledWith(@project_id, { method:"DELETE", url:"#{@settings.apis.clsi_priority.url}/project/#{@project_id}"})
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "_buildRequest", ->
|
|
describe "_buildRequest", ->
|
|
@@ -235,15 +242,15 @@ describe "ClsiManager", ->
|
|
|
|
|
|
|
|
describe "successfully", ->
|
|
describe "successfully", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @request.post = sinon.stub().callsArgWith(1, null, {statusCode: 204}, @body = { mock: "foo" })
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest = sinon.stub().callsArgWith(2, null, {statusCode: 204}, @body = { mock: "foo" })
|
|
|
@ClsiManager._postToClsi @project_id, @req, "standard", @callback
|
|
@ClsiManager._postToClsi @project_id, @req, "standard", @callback
|
|
|
|
|
|
|
|
it 'should send the request to the CLSI', ->
|
|
it 'should send the request to the CLSI', ->
|
|
|
url = "#{@settings.apis.clsi.url}/project/#{@project_id}/compile"
|
|
url = "#{@settings.apis.clsi.url}/project/#{@project_id}/compile"
|
|
|
- @request.post.calledWith({
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest.calledWith(@project_id, {
|
|
|
|
|
+ method: "POST",
|
|
|
url: url
|
|
url: url
|
|
|
json: @req
|
|
json: @req
|
|
|
- jar: false
|
|
|
|
|
}).should.equal true
|
|
}).should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the body and no error", ->
|
|
it "should call the callback with the body and no error", ->
|
|
@@ -251,7 +258,7 @@ describe "ClsiManager", ->
|
|
|
|
|
|
|
|
describe "when the CLSI returns an error", ->
|
|
describe "when the CLSI returns an error", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @request.post = sinon.stub().callsArgWith(1, null, {statusCode: 500}, @body = { mock: "foo" })
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest = sinon.stub().callsArgWith(2, null, {statusCode: 500}, @body = { mock: "foo" })
|
|
|
@ClsiManager._postToClsi @project_id, @req, "standard", @callback
|
|
@ClsiManager._postToClsi @project_id, @req, "standard", @callback
|
|
|
|
|
|
|
|
it "should call the callback with the body and the error", ->
|
|
it "should call the callback with the body and the error", ->
|
|
@@ -259,20 +266,20 @@ describe "ClsiManager", ->
|
|
|
|
|
|
|
|
describe "when the compiler is priority", ->
|
|
describe "when the compiler is priority", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @request.post = sinon.stub().callsArgWith(1, null, {statusCode: 500}, @body = { mock: "foo" })
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest = sinon.stub()
|
|
|
@ClsiManager._postToClsi @project_id, @req, "priority", @callback
|
|
@ClsiManager._postToClsi @project_id, @req, "priority", @callback
|
|
|
|
|
|
|
|
it "should use the clsi_priority url", ->
|
|
it "should use the clsi_priority url", ->
|
|
|
url = "#{@settings.apis.clsi_priority.url}/project/#{@project_id}/compile"
|
|
url = "#{@settings.apis.clsi_priority.url}/project/#{@project_id}/compile"
|
|
|
- @request.post.calledWith({
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest.calledWith(@project_id, {
|
|
|
|
|
+ method: "POST",
|
|
|
url: url
|
|
url: url
|
|
|
json: @req
|
|
json: @req
|
|
|
- jar: false
|
|
|
|
|
}).should.equal true
|
|
}).should.equal true
|
|
|
|
|
|
|
|
describe "wordCount", ->
|
|
describe "wordCount", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @request.get = sinon.stub().callsArgWith(1, null, {statusCode: 200}, @body = { mock: "foo" })
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest = sinon.stub().callsArgWith(2, null, {statusCode: 200}, @body = { mock: "foo" })
|
|
|
@ClsiManager._buildRequest = sinon.stub().callsArgWith(2, null, @req = { compile: { rootResourcePath: "rootfile.text", options: {} } })
|
|
@ClsiManager._buildRequest = sinon.stub().callsArgWith(2, null, @req = { compile: { rootResourcePath: "rootfile.text", options: {} } })
|
|
|
@ClsiManager._getCompilerUrl = sinon.stub().returns "compiler.url"
|
|
@ClsiManager._getCompilerUrl = sinon.stub().returns "compiler.url"
|
|
|
|
|
|
|
@@ -281,8 +288,8 @@ describe "ClsiManager", ->
|
|
|
@ClsiManager.wordCount @project_id, false, {}, @callback
|
|
@ClsiManager.wordCount @project_id, false, {}, @callback
|
|
|
|
|
|
|
|
it "should call wordCount with root file", ->
|
|
it "should call wordCount with root file", ->
|
|
|
- @request.get
|
|
|
|
|
- .calledWith({ url: "compiler.url/project/#{@project_id}/wordcount?file=rootfile.text" })
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest
|
|
|
|
|
+ .calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=rootfile.text" })
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
it "should call the callback", ->
|
|
@@ -293,8 +300,8 @@ describe "ClsiManager", ->
|
|
|
@ClsiManager.wordCount @project_id, "main.tex", {}, @callback
|
|
@ClsiManager.wordCount @project_id, "main.tex", {}, @callback
|
|
|
|
|
|
|
|
it "should call wordCount with param file", ->
|
|
it "should call wordCount with param file", ->
|
|
|
- @request.get
|
|
|
|
|
- .calledWith({ url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex" })
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest
|
|
|
|
|
+ .calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex" })
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "with image", ->
|
|
describe "with image", ->
|
|
@@ -303,6 +310,50 @@ describe "ClsiManager", ->
|
|
|
@ClsiManager.wordCount @project_id, "main.tex", {}, @callback
|
|
@ClsiManager.wordCount @project_id, "main.tex", {}, @callback
|
|
|
|
|
|
|
|
it "should call wordCount with file and image", ->
|
|
it "should call wordCount with file and image", ->
|
|
|
- @request.get
|
|
|
|
|
- .calledWith({ url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex&image=#{encodeURIComponent(@image)}" })
|
|
|
|
|
|
|
+ @ClsiManager._makeRequest
|
|
|
|
|
+ .calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex&image=#{encodeURIComponent(@image)}" })
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ describe "_makeRequest", ->
|
|
|
|
|
+
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @response = {there:"something"}
|
|
|
|
|
+ @request.callsArgWith(1, null, @response)
|
|
|
|
|
+ @opts =
|
|
|
|
|
+ method: "SOMETHIGN"
|
|
|
|
|
+ url: "http://a place on the web"
|
|
|
|
|
+
|
|
|
|
|
+ it "should process a request with a cookie jar", (done)->
|
|
|
|
|
+ @ClsiManager._makeRequest @project_id, @opts, =>
|
|
|
|
|
+ args = @request.args[0]
|
|
|
|
|
+ args[0].method.should.equal @opts.method
|
|
|
|
|
+ args[0].url.should.equal @opts.url
|
|
|
|
|
+ args[0].jar.should.equal @jar
|
|
|
|
|
+ done()
|
|
|
|
|
+
|
|
|
|
|
+ it "should set the cookie again on response as it might have changed", (done)->
|
|
|
|
|
+ @ClsiManager._makeRequest @project_id, @opts, =>
|
|
|
|
|
+ @ClsiCookieManager.setServerId.calledWith(@project_id, @response).should.equal true
|
|
|
|
|
+ done()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|