From 3be0425b45bce0c156ce4fbb51b356cd00f200d7 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 11 Sep 2015 10:21:05 -0300 Subject: [PATCH] add unit tests for wordcount --- .../coffee/Compile/ClsiManagerTests.coffee | 29 ++++++++++++++++++- .../Compile/CompileControllerTests.coffee | 19 ++++++++++++ .../coffee/Compile/CompileManagerTests.coffee | 19 ++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee b/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee index 8eda10fa56..66c21c2400 100644 --- a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee @@ -259,4 +259,31 @@ describe "ClsiManager", -> url: url json: @req jar: false - }).should.equal true \ No newline at end of file + }).should.equal true + + describe "wordCount", -> + beforeEach -> + @request.get = sinon.stub().callsArgWith(1, null, {statusCode: 200}, @body = { mock: "foo" }) + @ClsiManager._buildRequest = sinon.stub().callsArgWith(2, null, { compile: { rootResourcePath: "rootfile.text" } }) + @ClsiManager._getCompilerUrl = sinon.stub().returns "compiler.url" + + describe "with root file", -> + beforeEach -> + @ClsiManager.wordCount @project_id, false, {}, @callback + + it "should call wordCount with root file", -> + @request.get + .calledWith({ url: "compiler.url/project/#{@project_id}/wordcount?file=rootfile.text" }) + .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 + + it "should call wordCount with param file", -> + @request.get + .calledWith({ url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex" }) + .should.equal true diff --git a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee index 33239f53a6..7ac3bb0006 100644 --- a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee @@ -352,3 +352,22 @@ describe "CompileController", -> @CompileController.compileAndDownloadPdf @req, @res @CompileController.proxyToClsi.calledWith(@project_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"}) + @req.params = + Project_id: @project_id + @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) + .should.equal true + + it "should return a 200 and body", -> + @res.send + .calledWith(200, {content:"body"}) + .should.equal true diff --git a/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee b/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee index 9f4031e776..e68f5fa422 100644 --- a/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee @@ -259,3 +259,22 @@ describe "CompileManager", -> @CompileManager._checkIfAutoCompileLimitHasBeenHit true, (err, canCompile)=> canCompile.should.equal false done() + + 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 + + it "should look up the compile group to use", -> + @CompileManager.getProjectCompileLimits + .calledWith(@project_id) + .should.equal true + + it "should call wordCount for project", -> + @ClsiManager.wordCount + .calledWith(@project_id, false, @limits) + .should.equal true + + it "should call the callback", -> + @callback.called.should.equal true