Add a test for document size slightly over max doc length

This commit is contained in:
Eric Mc Sween 2020-05-11 10:41:32 -04:00
parent f99125c65a
commit 41c0899b0c

View file

@ -210,7 +210,21 @@ describe('Setting a document', function () {
})
})
describe('when the updated doc is too large for the body parser', function () {
const DOC_TOO_LARGE_TEST_CASES = [
{
desc: 'when the updated doc is too large for the body parser',
size: Settings.maxJsonRequestSize,
expectedStatusCode: 413
},
{
desc: 'when the updated doc is larger than the HTTP controller limit',
size: Settings.max_doc_length,
expectedStatusCode: 406
}
]
DOC_TOO_LARGE_TEST_CASES.forEach((testCase) => {
describe(testCase.desc, function () {
before(function (done) {
this.project_id = DocUpdaterClient.randomId()
this.doc_id = DocUpdaterClient.randomId()
@ -219,9 +233,7 @@ describe('Setting a document', function () {
version: this.version
})
this.newLines = []
while (
JSON.stringify(this.newLines).length <= Settings.maxJsonRequestSize
) {
while (JSON.stringify(this.newLines).length <= testCase.size) {
this.newLines.push('(a long line of text)'.repeat(10000))
}
DocUpdaterClient.setDocLines(
@ -247,8 +259,8 @@ describe('Setting a document', function () {
MockWebApi.setDocument.reset()
})
it('should return a 413 status code', function () {
this.statusCode.should.equal(413)
it(`should return a ${testCase.expectedStatusCode} status code`, function () {
this.statusCode.should.equal(testCase.expectedStatusCode)
})
it('should not send the updated doc lines to the web api', function () {
@ -263,6 +275,7 @@ describe('Setting a document', function () {
MockProjectHistoryApi.flushProject.called.should.equal(false)
})
})
})
describe('when the updated doc is large but under the bodyParser and HTTPController size limit', function () {
before(function (done) {