Pass image to wordcount end point in CLSI

This commit is contained in:
James Allen 2016-01-19 14:17:01 +00:00
parent 5125aa0089
commit ed5872702a
2 changed files with 15 additions and 2 deletions

View file

@ -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

View file

@ -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