Merge pull request #1924 from overleaf/ta-full-error

Don't Callback with String

GitOrigin-RevId: 82e3efb055ef197d95ff9c8a876bee0d6a0327a3
This commit is contained in:
Timothée Alby
2019-07-01 15:54:23 +02:00
committed by sharelatex
parent c86910a5ef
commit b1e8cb9cf0
13 changed files with 78 additions and 33 deletions
@@ -51,7 +51,7 @@ describe('EditorHttpController', function() {
this.AuthenticationController.getLoggedInUserId = sinon
.stub()
.returns(this.userId)
this.req = {}
this.req = { i18n: { translate: string => string } }
this.res = {
send: sinon.stub(),
sendStatus: sinon.stub(),
@@ -306,13 +306,27 @@ describe('EditorHttpController', function() {
})
describe('unsuccesfully', function() {
beforeEach(function() {
it('handle name too short', function() {
this.req.body.name = ''
return this.EditorHttpController.addDoc(this.req, this.res)
this.EditorHttpController.addDoc(this.req, this.res)
this.res.sendStatus.calledWith(400).should.equal(true)
})
it('should send back a bad request status code', function() {
return this.res.sendStatus.calledWith(400).should.equal(true)
it('handle too many files', function() {
this.EditorController.addDoc.yields(
new Error('project_has_to_many_files')
)
let res = {
status: status => {
status.should.equal(400)
return {
json: json => {
json.should.equal('project_has_to_many_files')
}
}
}
}
this.EditorHttpController.addDoc(this.req, res)
})
})
})
@@ -352,13 +366,44 @@ describe('EditorHttpController', function() {
})
describe('unsuccesfully', function() {
beforeEach(function() {
it('handle name too short', function() {
this.req.body.name = ''
return this.EditorHttpController.addFolder(this.req, this.res)
this.EditorHttpController.addFolder(this.req, this.res)
this.res.sendStatus.calledWith(400).should.equal(true)
})
it('should send back a bad request status code', function() {
return this.res.sendStatus.calledWith(400).should.equal(true)
it('handle too many files', function() {
this.EditorController.addFolder.yields(
new Error('project_has_to_many_files')
)
let res = {
status: status => {
status.should.equal(400)
return {
json: json => {
json.should.equal('project_has_to_many_files')
}
}
}
}
this.EditorHttpController.addFolder(this.req, res)
})
it('handle invalid element name', function() {
this.EditorController.addFolder.yields(
new Error('invalid element name')
)
let res = {
status: status => {
status.should.equal(400)
return {
json: json => {
json.should.equal('invalid_file_name')
}
}
}
}
this.EditorHttpController.addFolder(this.req, res)
})
})
})