extend tests for per-user compiles

This commit is contained in:
Brian Gough 2016-05-31 16:54:28 +01:00
parent ce1524cd07
commit 55a8e3cffe
3 changed files with 41 additions and 35 deletions

View file

@ -28,6 +28,7 @@ describe "ClsiManager", ->
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() }
"request": @request = sinon.stub()
@project_id = "project-id"
@user_id = "user-id"
@callback = sinon.stub()
describe "sendRequest", ->
@ -37,22 +38,22 @@ describe "ClsiManager", ->
describe "with a successful compile", ->
beforeEach ->
@ClsiManager._postToClsi = sinon.stub().callsArgWith(3, null, {
@ClsiManager._postToClsi = sinon.stub().callsArgWith(4, null, {
compile:
status: @status = "success"
outputFiles: [{
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/build/1234/output/output.pdf"
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/user/#{@user_id}/build/1234/output/output.pdf"
path: "output.pdf"
type: "pdf"
build: 1234
},{
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/build/1234/output/output.log"
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/user/#{@user_id}/build/1234/output/output.log"
path: "output.log"
type: "log"
build: 1234
}]
})
@ClsiManager.sendRequest @project_id, {compileGroup:"standard"}, @callback
@ClsiManager.sendRequest @project_id, @user_id, {compileGroup:"standard"}, @callback
it "should build the request", ->
@ClsiManager._buildRequest
@ -61,17 +62,17 @@ describe "ClsiManager", ->
it "should send the request to the CLSI", ->
@ClsiManager._postToClsi
.calledWith(@project_id, @request, "standard")
.calledWith(@project_id, @user_id, @request, "standard")
.should.equal true
it "should call the callback with the status and output files", ->
outputFiles = [{
url: "/project/#{@project_id}/build/1234/output/output.pdf"
url: "/project/#{@project_id}/user/#{@user_id}/build/1234/output/output.pdf"
path: "output.pdf"
type: "pdf"
build: 1234
},{
url: "/project/#{@project_id}/build/1234/output/output.log"
url: "/project/#{@project_id}/user/#{@user_id}/build/1234/output/output.log"
path: "output.log"
type: "log"
build: 1234
@ -80,11 +81,11 @@ describe "ClsiManager", ->
describe "with a failed compile", ->
beforeEach ->
@ClsiManager._postToClsi = sinon.stub().callsArgWith(3, null, {
@ClsiManager._postToClsi = sinon.stub().callsArgWith(4, null, {
compile:
status: @status = "failure"
})
@ClsiManager.sendRequest @project_id, {}, @callback
@ClsiManager.sendRequest @project_id, @user_id, {}, @callback
it "should call the callback with a failure statue", ->
@callback.calledWith(null, @status).should.equal true
@ -95,11 +96,11 @@ describe "ClsiManager", ->
describe "with the standard compileGroup", ->
beforeEach ->
@ClsiManager.deleteAuxFiles @project_id, {compileGroup: "standard"}, @callback
@ClsiManager.deleteAuxFiles @project_id, @user_id, {compileGroup: "standard"}, @callback
it "should call the delete method in the standard CLSI", ->
@ClsiManager._makeRequest
.calledWith(@project_id, { method:"DELETE", url:"#{@settings.apis.clsi.url}/project/#{@project_id}"})
.calledWith(@project_id, { method:"DELETE", url:"#{@settings.apis.clsi.url}/project/#{@project_id}/user/#{@user_id}"})
.should.equal true
it "should call the callback", ->
@ -239,10 +240,10 @@ describe "ClsiManager", ->
describe "successfully", ->
beforeEach ->
@ClsiManager._makeRequest = sinon.stub().callsArgWith(2, null, {statusCode: 204}, @body = { mock: "foo" })
@ClsiManager._postToClsi @project_id, @req, "standard", @callback
@ClsiManager._postToClsi @project_id, @user_id, @req, "standard", @callback
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}/user/#{@user_id}/compile"
@ClsiManager._makeRequest.calledWith(@project_id, {
method: "POST",
url: url
@ -255,7 +256,7 @@ describe "ClsiManager", ->
describe "when the CLSI returns an error", ->
beforeEach ->
@ClsiManager._makeRequest = sinon.stub().callsArgWith(2, null, {statusCode: 500}, @body = { mock: "foo" })
@ClsiManager._postToClsi @project_id, @req, "standard", @callback
@ClsiManager._postToClsi @project_id, @user_id, @req, "standard", @callback
it "should call the callback with the body and the error", ->
@callback.calledWith(new Error("CLSI returned non-success code: 500"), @body).should.equal true
@ -265,37 +266,36 @@ describe "ClsiManager", ->
beforeEach ->
@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._getCompilerUrl = sinon.stub().returns "compiler.url"
describe "with root file", ->
beforeEach ->
@ClsiManager.wordCount @project_id, false, {}, @callback
@ClsiManager.wordCount @project_id, @user_id, false, {}, @callback
it "should call wordCount with root file", ->
@ClsiManager._makeRequest
.calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=rootfile.text" })
.should.equal true
.calledWith(@project_id, {method: "GET", url: "http://clsi.example.com/project/#{@project_id}/user/#{@user_id}/wordcount", qs: {file: "rootfile.text",image:undefined}})
.should.equal true
it "should call the callback", ->
@callback.called.should.equal true
describe "with param file", ->
beforeEach ->
@ClsiManager.wordCount @project_id, "main.tex", {}, @callback
@ClsiManager.wordCount @project_id, @user_id, "main.tex", {}, @callback
it "should call wordCount with param file", ->
@ClsiManager._makeRequest
.calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex" })
.calledWith(@project_id, { method: "GET", url: "http://clsi.example.com/project/#{@project_id}/user/#{@user_id}/wordcount", qs:{file:"main.tex",image:undefined}})
.should.equal true
describe "with image", ->
beforeEach ->
@req.compile.options.imageName = @image = "example.com/mock/image"
@ClsiManager.wordCount @project_id, "main.tex", {}, @callback
@ClsiManager.wordCount @project_id, @user_id, "main.tex", {}, @callback
it "should call wordCount with file and image", ->
@ClsiManager._makeRequest
.calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex&image=#{encodeURIComponent(@image)}" })
.calledWith(@project_id, { method: "GET", url: "http://clsi.example.com/project/#{@project_id}/user/#{@user_id}/wordcount", qs:{file:"main.tex",image:@image}})
.should.equal true

View file

@ -45,13 +45,13 @@ describe "CompileController", ->
@next = sinon.stub()
@req = new MockRequest()
@res = new MockResponse()
@AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id = "mock-user-id")
describe "compile", ->
beforeEach ->
@req.params =
Project_id: @project_id
@req.session = {}
@AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id = "mock-user-id")
@CompileManager.compile = sinon.stub().callsArgWith(3, null, @status = "success", @outputFiles = ["mock-output-files"])
describe "when not an auto compile", ->
@ -359,7 +359,7 @@ describe "CompileController", ->
describe "deleteAuxFiles", ->
beforeEach ->
@CompileManager.deleteAuxFiles = sinon.stub().callsArg(1)
@CompileManager.deleteAuxFiles = sinon.stub().callsArg(2)
@req.params =
Project_id: @project_id
@res.sendStatus = sinon.stub()
@ -380,6 +380,8 @@ describe "CompileController", ->
@req =
params:
project_id:@project_id
query:
isolated: "true"
@CompileManager.compile.callsArgWith(3)
@CompileController.proxyToClsi = sinon.stub()
@res =
@ -392,21 +394,25 @@ describe "CompileController", ->
it "should proxy the res to the clsi with correct url", (done)->
@CompileController.compileAndDownloadPdf @req, @res
@CompileController.proxyToClsi.calledWith(@project_id, "/project/#{@project_id}/output/output.pdf", @req, @res).should.equal true
sinon.assert.calledWith @CompileController.proxyToClsi, @project_id, @user_id, "/project/#{@project_id}/output/output.pdf", @req, @res
@CompileController.proxyToClsi.calledWith(@project_id, @user_id, "/project/#{@project_id}/output/output.pdf", @req, @res).should.equal true
done()
describe "wordCount", ->
beforeEach ->
@CompileManager.wordCount = sinon.stub().callsArgWith(2, null, {content:"body"})
@CompileManager.wordCount = sinon.stub().callsArgWith(3, null, {content:"body"})
@req.params =
Project_id: @project_id
@req.query =
isolated: "true"
@res.send = sinon.stub()
@res.contentType = sinon.stub()
@CompileController.wordCount @req, @res, @next
it "should proxy to the CLSI", ->
@CompileManager.wordCount
.calledWith(@project_id, false)
.calledWith(@project_id, @user_id, false)
.should.equal true
it "should return a 200 and body", ->

View file

@ -42,7 +42,7 @@ describe "CompileManager", ->
@CompileManager._ensureRootDocumentIsSet = sinon.stub().callsArgWith(1, null)
@DocumentUpdaterHandler.flushProjectToMongo = sinon.stub().callsArgWith(1, null)
@CompileManager.getProjectCompileLimits = sinon.stub().callsArgWith(1, null, @limits)
@ClsiManager.sendRequest = sinon.stub().callsArgWith(2, null, @status = "mock-status", @outputFiles = "mock output files", @output = "mock output")
@ClsiManager.sendRequest = sinon.stub().callsArgWith(3, null, @status = "mock-status", @outputFiles = "mock output files", @output = "mock output")
describe "succesfully", ->
beforeEach ->
@ -71,7 +71,7 @@ describe "CompileManager", ->
it "should run the compile with the compile limits", ->
@ClsiManager.sendRequest
.calledWith(@project_id, {
.calledWith(@project_id, undefined, {
timeout: @limits.timeout
})
.should.equal true
@ -135,8 +135,8 @@ describe "CompileManager", ->
describe "deleteAuxFiles", ->
beforeEach ->
@CompileManager.getProjectCompileLimits = sinon.stub().callsArgWith 1, null, @limits = { compileGroup: "mock-compile-group" }
@ClsiManager.deleteAuxFiles = sinon.stub().callsArg(2)
@CompileManager.deleteAuxFiles @project_id, @callback
@ClsiManager.deleteAuxFiles = sinon.stub().callsArg(3)
@CompileManager.deleteAuxFiles @project_id, @user_id, @callback
it "should look up the compile group to use", ->
@CompileManager.getProjectCompileLimits
@ -145,7 +145,7 @@ describe "CompileManager", ->
it "should delete the aux files", ->
@ClsiManager.deleteAuxFiles
.calledWith(@project_id, @limits)
.calledWith(@project_id, @user_id, @limits)
.should.equal true
it "should call the callback", ->
@ -260,8 +260,8 @@ describe "CompileManager", ->
describe "wordCount", ->
beforeEach ->
@CompileManager.getProjectCompileLimits = sinon.stub().callsArgWith 1, null, @limits = { compileGroup: "mock-compile-group" }
@ClsiManager.wordCount = sinon.stub().callsArg(3)
@CompileManager.wordCount @project_id, false, @callback
@ClsiManager.wordCount = sinon.stub().callsArg(4)
@CompileManager.wordCount @project_id, @user_id, false, @callback
it "should look up the compile group to use", ->
@CompileManager.getProjectCompileLimits
@ -270,7 +270,7 @@ describe "CompileManager", ->
it "should call wordCount for project", ->
@ClsiManager.wordCount
.calledWith(@project_id, false, @limits)
.calledWith(@project_id, @user_id, false, @limits)
.should.equal true
it "should call the callback", ->