add unit tests

This commit is contained in:
Brian Gough 2018-08-13 10:48:11 +01:00
parent 19dfe5fc8b
commit c2828c8ca5
3 changed files with 44 additions and 0 deletions

View file

@ -32,6 +32,7 @@ describe "EditorController", ->
'../Project/ProjectEntityUpdateHandler' : @ProjectEntityUpdateHandler = {}
'../Project/ProjectOptionsHandler' : @ProjectOptionsHandler =
setCompiler: sinon.stub().yields()
setImageName: sinon.stub().yields()
setSpellCheckLanguage: sinon.stub().yields()
'../Project/ProjectDetailsHandler': @ProjectDetailsHandler =
setProjectDescription: sinon.stub().yields()
@ -377,6 +378,19 @@ describe "EditorController", ->
.calledWith(@project_id, "compilerUpdated", @compiler)
.should.equal true
describe "setImageName", ->
beforeEach ->
@imageName = "texlive-1234.5"
@EditorController.setImageName @project_id, @imageName, @callback
it "should send the new imageName and project id to the project options handler", ->
@ProjectOptionsHandler.setImageName
.calledWith(@project_id, @imageName)
.should.equal true
@EditorRealTimeController.emitToRoom
.calledWith(@project_id, "imageNameUpdated", @imageName)
.should.equal true
describe "setSpellCheckLanguage", ->
beforeEach ->
@languageCode = "fr"

View file

@ -145,6 +145,18 @@ describe "ProjectController", ->
done()
@ProjectController.updateProjectSettings @req, @res
it "should update the imageName", (done) ->
@EditorController.setImageName = sinon.stub().callsArg(2)
@req.body =
imageName: @imageName = "texlive-1234.5"
@res.sendStatus = (code) =>
@EditorController.setImageName
.calledWith(@project_id, @imageName)
.should.equal true
code.should.equal 204
done()
@ProjectController.updateProjectSettings @req, @res
it "should update the spell check language", (done) ->
@EditorController.setSpellCheckLanguage = sinon.stub().callsArg(2)
@req.body =

View file

@ -19,6 +19,11 @@ describe 'creating a project', ->
{name: "English", code: "en"}
{name: "French", code: "fr"}
]
imageRoot: "docker-repo/subdir"
allowedImageNames: [
{imageName: "texlive-0000.0", imageDesc: "test image 0"}
{imageName: "texlive-1234.5", imageDesc: "test image 1"}
]
'logger-sharelatex':
log:->
err:->
@ -37,6 +42,19 @@ describe 'creating a project', ->
@projectModel.update.called.should.equal false
done()
describe 'Setting the imageName', ->
it 'should perform and update on mongo', (done)->
@handler.setImageName project_id, "texlive-1234.5", (err)=>
args = @projectModel.update.args[0]
args[0]._id.should.equal project_id
args[1].imageName.should.equal "docker-repo/subdir/texlive-1234.5"
done()
@projectModel.update.args[0][3]()
it 'should not perform and update on mongo if it is not a reconised compiler', (done)->
@handler.setImageName project_id, "something", (err)=>
@projectModel.update.called.should.equal false
done()
describe "setting the spellCheckLanguage", ->