Просмотр исходного кода

Pass image to wordcount end point in CLSI

James Allen 10 лет назад
Родитель
Сommit
ed5872702a

+ 4 - 1
services/web/app/coffee/Features/Compile/ClsiManager.coffee

@@ -111,8 +111,11 @@ module.exports = ClsiManager =
 		ClsiManager._buildRequest project_id, options, (error, req) ->
 			compilerUrl = ClsiManager._getCompilerUrl(options?.compileGroup)
 			filename = file || req?.compile?.rootResourcePath
+			wordcount_url = "#{compilerUrl}/project/#{project_id}/wordcount?file=#{encodeURIComponent(filename)}"
+			if req.compile.options.imageName?
+				wordcount_url += "&image=#{encodeURIComponent(req.compile.options.imageName)}"
 			request.get {
-				url:  "#{compilerUrl}/project/#{project_id}/wordcount?file=#{filename}"
+				url: wordcount_url
 			}, (error, response, body) ->
 				return callback(error) if error?
 				if 200 <= response.statusCode < 300

+ 11 - 1
services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee

@@ -266,7 +266,7 @@ describe "ClsiManager", ->
 	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._buildRequest = sinon.stub().callsArgWith(2, null, @req = { compile: { rootResourcePath: "rootfile.text", options: {} } })
 			@ClsiManager._getCompilerUrl = sinon.stub().returns "compiler.url"
 
 		describe "with root file", ->
@@ -289,3 +289,13 @@ describe "ClsiManager", ->
 				@request.get
 					.calledWith({ url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex" })
 					.should.equal true
+					
+		describe "with image", ->
+			beforeEach ->
+				@req.compile.options.imageName = @image = "example.com/mock/image"
+				@ClsiManager.wordCount @project_id, "main.tex", {}, @callback
+
+			it "should call wordCount with file and image", ->
+				@request.get
+					.calledWith({ url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex&image=#{encodeURIComponent(@image)}" })
+					.should.equal true