|
|
@@ -21,11 +21,58 @@ describe "CompileController", ->
|
|
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
|
|
"../../infrastructure/Metrics": @Metrics = { inc: sinon.stub() }
|
|
|
"./CompileManager":@CompileManager
|
|
|
+ "../Authentication/AuthenticationController": @AuthenticationController = {}
|
|
|
@project_id = "project-id"
|
|
|
@next = sinon.stub()
|
|
|
@req = new MockRequest()
|
|
|
@res = new MockResponse()
|
|
|
|
|
|
+ describe "compile", ->
|
|
|
+ describe "when not an auto compile", ->
|
|
|
+ beforeEach ->
|
|
|
+ @req.params =
|
|
|
+ Project_id: @project_id
|
|
|
+ @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"])
|
|
|
+ @CompileController.compile @req, @res, @next
|
|
|
+
|
|
|
+ it "should look up the user id", ->
|
|
|
+ @AuthenticationController.getLoggedInUserId
|
|
|
+ .calledWith(@req)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should do the compile without the auto compile flag", ->
|
|
|
+ @CompileManager.compile
|
|
|
+ .calledWith(@project_id, @user_id, { isAutoCompile: false })
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should set the content-type of the response to application/json", ->
|
|
|
+ @res.contentType
|
|
|
+ .calledWith("application/json")
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should send a successful response reporting the status and files", ->
|
|
|
+ @res.statusCode.should.equal 200
|
|
|
+ @res.body.should.equal JSON.stringify({
|
|
|
+ status: @status
|
|
|
+ outputFiles: @outputFiles
|
|
|
+ })
|
|
|
+
|
|
|
+ describe "when an auto compile", ->
|
|
|
+ beforeEach ->
|
|
|
+ @req.params =
|
|
|
+ Project_id: @project_id
|
|
|
+ @req.query =
|
|
|
+ auto_compile: "true"
|
|
|
+ @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"])
|
|
|
+ @CompileController.compile @req, @res, @next
|
|
|
+
|
|
|
+ it "should do the compile with the auto compile flag", ->
|
|
|
+ @CompileManager.compile
|
|
|
+ .calledWith(@project_id, @user_id, { isAutoCompile: true })
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
describe "downloadPdf", ->
|
|
|
beforeEach ->
|
|
|
@req.params =
|