2020-05-06 06:11:36 -04:00
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = '../../../../app/js/PersistenceManager.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const Errors = require('../../../../app/js/Errors')
|
|
|
|
|
|
|
|
describe('PersistenceManager', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.request = sinon.stub()
|
|
|
|
this.request.defaults = () => this.request
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics = {
|
|
|
|
Timer: class Timer {},
|
|
|
|
inc: sinon.stub(),
|
|
|
|
}
|
|
|
|
this.Metrics.Timer.prototype.done = sinon.stub()
|
|
|
|
this.Settings = {}
|
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
this.PersistenceManager = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
requestretry: this.request,
|
2021-08-19 10:40:31 -04:00
|
|
|
'@overleaf/settings': this.Settings,
|
|
|
|
'./Metrics': this.Metrics,
|
2021-07-13 07:04:42 -04:00
|
|
|
'./Errors': Errors,
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
this.project_id = 'project-id-123'
|
|
|
|
this.projectHistoryId = 'history-id-123'
|
|
|
|
this.doc_id = 'doc-id-123'
|
|
|
|
this.lines = ['one', 'two', 'three']
|
|
|
|
this.version = 42
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
this.ranges = { comments: 'mock', entries: 'mock' }
|
|
|
|
this.pathname = '/a/b/c.tex'
|
|
|
|
this.lastUpdatedAt = Date.now()
|
|
|
|
this.lastUpdatedBy = 'last-author-id'
|
2024-02-09 09:09:40 -05:00
|
|
|
this.historyRangesSupport = false
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Settings.apis = {
|
2020-05-06 06:11:36 -04:00
|
|
|
web: {
|
|
|
|
url: (this.url = 'www.example.com'),
|
2024-02-06 04:34:15 -05:00
|
|
|
user: (this.user = 'overleaf'),
|
2021-07-13 07:04:42 -04:00
|
|
|
pass: (this.pass = 'password'),
|
|
|
|
},
|
2021-08-19 10:40:31 -04:00
|
|
|
}
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('getDoc', function () {
|
|
|
|
beforeEach(function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.webResponse = {
|
2020-05-06 06:11:36 -04:00
|
|
|
lines: this.lines,
|
|
|
|
version: this.version,
|
|
|
|
ranges: this.ranges,
|
|
|
|
pathname: this.pathname,
|
2021-07-13 07:04:42 -04:00
|
|
|
projectHistoryId: this.projectHistoryId,
|
2024-02-09 09:09:40 -05:00
|
|
|
historyRangesSupport: this.historyRangesSupport,
|
2021-08-19 10:40:31 -04:00
|
|
|
}
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('with a successful response from the web api', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.request.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
{ statusCode: 200 },
|
|
|
|
JSON.stringify(this.webResponse)
|
|
|
|
)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.getDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the web api', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.request
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith({
|
|
|
|
url: `${this.url}/project/${this.project_id}/doc/${this.doc_id}`,
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
2021-07-13 07:04:42 -04:00
|
|
|
accept: 'application/json',
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
auth: {
|
|
|
|
user: this.user,
|
|
|
|
pass: this.pass,
|
2021-07-13 07:04:42 -04:00
|
|
|
sendImmediately: true,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
jar: false,
|
2021-07-13 07:04:42 -04:00
|
|
|
timeout: 5000,
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the callback with the doc lines, version and ranges', function () {
|
2023-09-05 17:07:11 -04:00
|
|
|
this.callback
|
|
|
|
.calledWith(
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
2024-02-09 09:09:40 -05:00
|
|
|
this.projectHistoryId,
|
|
|
|
this.historyRangesSupport
|
2023-09-05 17:07:11 -04:00
|
|
|
)
|
|
|
|
.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith('getDoc', 1, { status: 200 })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('with the peek option', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.request.yields(
|
|
|
|
null,
|
|
|
|
{ statusCode: 200 },
|
|
|
|
JSON.stringify(this.webResponse)
|
|
|
|
)
|
|
|
|
this.PersistenceManager.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{ peek: true },
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the web api with a peek param', function () {
|
|
|
|
this.request
|
|
|
|
.calledWith({
|
|
|
|
url: `${this.url}/project/${this.project_id}/doc/${this.doc_id}`,
|
|
|
|
qs: { peek: 'true' },
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
accept: 'application/json',
|
|
|
|
},
|
|
|
|
auth: {
|
|
|
|
user: this.user,
|
|
|
|
pass: this.pass,
|
|
|
|
sendImmediately: true,
|
|
|
|
},
|
|
|
|
jar: false,
|
|
|
|
timeout: 5000,
|
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('when request returns an error', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.error = new Error('oops')
|
|
|
|
this.error.code = 'EOOPS'
|
|
|
|
this.request.callsArgWith(1, this.error, null, null)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.getDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-02-24 09:09:19 -05:00
|
|
|
it('should return a generic connection error', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2021-02-24 09:09:19 -05:00
|
|
|
.calledWith(
|
|
|
|
sinon.match
|
|
|
|
.instanceOf(Error)
|
|
|
|
.and(sinon.match.has('message', 'error connecting to web API'))
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith('getDoc', 1, { status: 'EOOPS' })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the request returns 404', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.request.callsArgWith(1, null, { statusCode: 404 }, '')
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.getDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return a NotFoundError', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith('getDoc', 1, { status: 404 })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-07-06 05:50:16 -04:00
|
|
|
describe('when the request returns 413', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.request.callsArgWith(1, null, { statusCode: 413 }, '')
|
|
|
|
this.PersistenceManager.getDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return a FileTooLargeError', function () {
|
|
|
|
this.callback
|
|
|
|
.calledWith(sinon.match.instanceOf(Errors.FileTooLargeError))
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
|
|
|
.calledWith('getDoc', 1, { status: 413 })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('when the request returns an error status code', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.getDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return an error', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Error))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith('getDoc', 1, { status: 500 })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when request returns an doc without lines', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
delete this.webResponse.lines
|
|
|
|
this.request.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
{ statusCode: 200 },
|
|
|
|
JSON.stringify(this.webResponse)
|
|
|
|
)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.getDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should return and error', function () {
|
|
|
|
this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Error))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when request returns an doc without a version', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
delete this.webResponse.version
|
|
|
|
this.request.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
{ statusCode: 200 },
|
|
|
|
JSON.stringify(this.webResponse)
|
|
|
|
)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.getDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should return and error', function () {
|
|
|
|
this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Error))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('when request returns an doc without a pathname', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
delete this.webResponse.pathname
|
|
|
|
this.request.callsArgWith(
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
{ statusCode: 200 },
|
|
|
|
JSON.stringify(this.webResponse)
|
|
|
|
)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.getDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should return and error', function () {
|
|
|
|
this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Error))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('setDoc', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('with a successful response from the web api', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.request.callsArgWith(1, null, { statusCode: 200 })
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.setDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.lastUpdatedAt,
|
|
|
|
this.lastUpdatedBy,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the web api', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.request
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith({
|
|
|
|
url: `${this.url}/project/${this.project_id}/doc/${this.doc_id}`,
|
|
|
|
json: {
|
|
|
|
lines: this.lines,
|
|
|
|
version: this.version,
|
|
|
|
ranges: this.ranges,
|
|
|
|
lastUpdatedAt: this.lastUpdatedAt,
|
2021-07-13 07:04:42 -04:00
|
|
|
lastUpdatedBy: this.lastUpdatedBy,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
auth: {
|
|
|
|
user: this.user,
|
|
|
|
pass: this.pass,
|
2021-07-13 07:04:42 -04:00
|
|
|
sendImmediately: true,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
jar: false,
|
2021-07-13 07:04:42 -04:00
|
|
|
timeout: 5000,
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the callback without error', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback.calledWith(null).should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith('setDoc', 1, { status: 200 })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when request returns an error', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.error = new Error('oops')
|
|
|
|
this.error.code = 'EOOPS'
|
|
|
|
this.request.callsArgWith(1, this.error, null, null)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.setDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.lastUpdatedAt,
|
|
|
|
this.lastUpdatedBy,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-02-24 09:09:19 -05:00
|
|
|
it('should return a generic connection error', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2021-02-24 09:09:19 -05:00
|
|
|
.calledWith(
|
|
|
|
sinon.match
|
|
|
|
.instanceOf(Error)
|
|
|
|
.and(sinon.match.has('message', 'error connecting to web API'))
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith('setDoc', 1, { status: 'EOOPS' })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the request returns 404', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.request.callsArgWith(1, null, { statusCode: 404 }, '')
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.setDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.lastUpdatedAt,
|
|
|
|
this.lastUpdatedBy,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return a NotFoundError', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith('setDoc', 1, { status: 404 })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-07-06 05:50:16 -04:00
|
|
|
describe('when the request returns 413', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.request.callsArgWith(1, null, { statusCode: 413 }, '')
|
|
|
|
this.PersistenceManager.setDoc(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.lastUpdatedAt,
|
|
|
|
this.lastUpdatedBy,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return a FileTooLargeError', function () {
|
|
|
|
this.callback
|
|
|
|
.calledWith(sinon.match.instanceOf(Errors.FileTooLargeError))
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
|
|
|
.calledWith('setDoc', 1, { status: 413 })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('when the request returns an error status code', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.request.callsArgWith(1, null, { statusCode: 500 }, '')
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.setDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.lastUpdatedAt,
|
|
|
|
this.lastUpdatedBy,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return an error', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Error))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should time the execution', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should increment the metric', function () {
|
|
|
|
this.Metrics.inc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith('setDoc', 1, { status: 500 })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|