2020-02-16 09:03:03 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-16 09:03:02 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-16 09:03:09 -05:00
|
|
|
const sinon = require('sinon')
|
2020-08-24 05:01:08 -04:00
|
|
|
const { ObjectId } = require('mongodb')
|
2020-02-16 09:03:09 -05:00
|
|
|
const DocstoreApp = require('./helpers/DocstoreApp')
|
|
|
|
|
|
|
|
const DocstoreClient = require('./helpers/DocstoreClient')
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('Applying updates to a doc', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
this.project_id = ObjectId()
|
|
|
|
this.doc_id = ObjectId()
|
|
|
|
this.originalLines = ['original', 'lines']
|
|
|
|
this.newLines = ['new', 'lines']
|
|
|
|
this.originalRanges = {
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
id: ObjectId().toString(),
|
|
|
|
op: { i: 'foo', p: 3 },
|
|
|
|
meta: {
|
|
|
|
user_id: ObjectId().toString(),
|
2021-07-13 07:04:48 -04:00
|
|
|
ts: new Date().toString(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-02-16 09:03:09 -05:00
|
|
|
}
|
|
|
|
this.newRanges = {
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
id: ObjectId().toString(),
|
|
|
|
op: { i: 'bar', p: 6 },
|
|
|
|
meta: {
|
|
|
|
user_id: ObjectId().toString(),
|
2021-07-13 07:04:48 -04:00
|
|
|
ts: new Date().toString(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-02-16 09:03:09 -05:00
|
|
|
}
|
|
|
|
this.version = 42
|
|
|
|
return DocstoreApp.ensureRunning(() => {
|
|
|
|
return DocstoreClient.createDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.originalLines,
|
|
|
|
this.version,
|
|
|
|
this.originalRanges,
|
2021-07-13 07:04:48 -04:00
|
|
|
error => {
|
2020-02-16 09:03:09 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when nothing has been updated', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.originalLines,
|
|
|
|
this.version,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return modified = false', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.modified.should.equal(false)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should not update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.originalLines)
|
|
|
|
doc.version.should.equal(this.version)
|
|
|
|
doc.ranges.should.deep.equal(this.originalRanges)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the lines have changed', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.newLines,
|
|
|
|
this.version,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return modified = true', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.modified.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return the rev', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.rev.should.equal(2)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.newLines)
|
|
|
|
doc.version.should.equal(this.version)
|
|
|
|
doc.ranges.should.deep.equal(this.originalRanges)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the version has changed', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.originalLines,
|
|
|
|
this.version + 1,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return modified = true', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.modified.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return the rev', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.rev.should.equal(1)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.originalLines)
|
|
|
|
doc.version.should.equal(this.version + 1)
|
|
|
|
doc.ranges.should.deep.equal(this.originalRanges)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the ranges have changed', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.originalLines,
|
|
|
|
this.version,
|
|
|
|
this.newRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return modified = true', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.modified.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return the rev', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.rev.should.equal(2)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.originalLines)
|
|
|
|
doc.version.should.equal(this.version)
|
|
|
|
doc.ranges.should.deep.equal(this.newRanges)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc does not exist', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
this.missing_doc_id = ObjectId()
|
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.missing_doc_id,
|
|
|
|
this.originalLines,
|
|
|
|
0,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should create the doc', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.rev.should.equal(1)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should be retreivable', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.missing_doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.originalLines)
|
|
|
|
doc.version.should.equal(0)
|
|
|
|
doc.ranges.should.deep.equal(this.originalRanges)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when malformed doc lines are provided', function () {
|
|
|
|
describe('when the lines are not an array', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{ foo: 'bar' },
|
|
|
|
this.version,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return 400', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.res.statusCode.should.equal(400)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should not update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.originalLines)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return describe('when the lines are not present', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
null,
|
|
|
|
this.version,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return 400', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.res.statusCode.should.equal(400)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should not update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.originalLines)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when no version is provided', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.originalLines,
|
|
|
|
null,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return 400', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.res.statusCode.should.equal(400)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should not update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.originalLines)
|
|
|
|
doc.version.should.equal(this.version)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the content is large', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
const line = new Array(1025).join('x') // 1kb
|
|
|
|
this.largeLines = Array.apply(null, Array(1024)).map(() => line) // 1mb
|
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.largeLines,
|
|
|
|
this.version,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return modified = true', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.modified.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.largeLines)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when there is a large json payload', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
const line = new Array(1025).join('x') // 1kb
|
|
|
|
this.largeLines = Array.apply(null, Array(1024)).map(() => line) // 1kb
|
|
|
|
this.originalRanges.padding = Array.apply(null, Array(2049)).map(
|
|
|
|
() => line
|
|
|
|
) // 2mb + 1kb
|
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.largeLines,
|
|
|
|
this.version,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return modified = true', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.body.modified.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.largeLines)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the document body is too large', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
const line = new Array(1025).join('x') // 1kb
|
|
|
|
this.largeLines = Array.apply(null, Array(2049)).map(() => line) // 2mb + 1kb
|
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.largeLines,
|
|
|
|
this.version,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return 413', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.res.statusCode.should.equal(413)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should report body too large', function () {
|
2020-02-16 09:03:09 -05:00
|
|
|
return this.res.body.should.equal('document body too large')
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should not update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.originalLines)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return describe('when the json payload is too large', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
const line = new Array(1025).join('x') // 1kb
|
|
|
|
this.largeLines = Array.apply(null, Array(1024)).map(() => line) // 1kb
|
2022-03-04 10:17:16 -05:00
|
|
|
this.originalRanges.padding = Array.apply(null, Array(6144)).map(
|
2020-02-16 09:03:09 -05:00
|
|
|
() => line
|
2022-03-04 10:17:16 -05:00
|
|
|
) // 6mb
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.updateDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.largeLines,
|
|
|
|
this.version,
|
|
|
|
this.originalRanges,
|
|
|
|
(error, res, body) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should not update the doc in the API', function (done) {
|
2020-02-16 09:03:09 -05:00
|
|
|
return DocstoreClient.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
(error, res, doc) => {
|
2021-10-27 05:49:18 -04:00
|
|
|
if (error) return done(error)
|
2020-02-16 09:03:09 -05:00
|
|
|
doc.lines.should.deep.equal(this.originalLines)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|