2020-05-06 06:11:36 -04:00
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath = '../../../../app/js/DocumentManager.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const Errors = require('../../../../app/js/Errors')
|
|
|
|
const tk = require('timekeeper')
|
|
|
|
|
|
|
|
describe('DocumentManager', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
tk.freeze(new Date())
|
2021-08-19 10:40:31 -04:00
|
|
|
this.Metrics = {
|
|
|
|
Timer: class Timer {},
|
|
|
|
}
|
|
|
|
this.Metrics.Timer.prototype.done = sinon.stub()
|
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
this.DocumentManager = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'./RedisManager': (this.RedisManager = {}),
|
|
|
|
'./ProjectHistoryRedisManager': (this.ProjectHistoryRedisManager = {}),
|
|
|
|
'./PersistenceManager': (this.PersistenceManager = {}),
|
|
|
|
'./HistoryManager': (this.HistoryManager = {
|
|
|
|
flushDocChangesAsync: sinon.stub(),
|
2021-07-13 07:04:42 -04:00
|
|
|
flushProjectChangesAsync: sinon.stub(),
|
2020-05-06 06:11:36 -04:00
|
|
|
}),
|
2021-08-19 10:40:31 -04:00
|
|
|
'./Metrics': this.Metrics,
|
2020-05-06 06:11:36 -04:00
|
|
|
'./RealTimeRedisManager': (this.RealTimeRedisManager = {}),
|
|
|
|
'./DiffCodec': (this.DiffCodec = {}),
|
|
|
|
'./UpdateManager': (this.UpdateManager = {}),
|
2020-05-15 14:29:49 -04:00
|
|
|
'./RangesManager': (this.RangesManager = {}),
|
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.projectHistoryType = 'project-history'
|
|
|
|
this.doc_id = 'doc-id-123'
|
|
|
|
this.user_id = 1234
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
this.lines = ['one', 'two', 'three']
|
|
|
|
this.version = 42
|
|
|
|
this.ranges = { comments: 'mock', entries: 'mock' }
|
|
|
|
this.pathname = '/a/b/c.tex'
|
|
|
|
this.unflushedTime = Date.now()
|
|
|
|
this.lastUpdatedAt = Date.now()
|
2021-08-19 10:40:31 -04:00
|
|
|
this.lastUpdatedBy = 'last-author-id'
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
tk.reset()
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('flushAndDeleteDoc', function () {
|
|
|
|
describe('successfully', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.RedisManager.removeDocFromMemory = sinon.stub().callsArg(2)
|
|
|
|
this.DocumentManager.flushDocIfLoaded = sinon.stub().callsArgWith(2)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushAndDeleteDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should flush the doc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushDocIfLoaded
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should remove the doc from redis', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.removeDocFromMemory
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.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 flush to the history api', function () {
|
|
|
|
this.HistoryManager.flushDocChangesAsync
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWithExactly(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('when a flush error occurs', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.DocumentManager.flushDocIfLoaded = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, new Error('boom!'))
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.removeDocFromMemory = sinon.stub().callsArg(2)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not remove the doc from redis', function (done) {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushAndDeleteDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{},
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2020-05-06 06:11:36 -04:00
|
|
|
error.should.exist
|
|
|
|
this.RedisManager.removeDocFromMemory.called.should.equal(false)
|
2021-08-19 10:40:31 -04:00
|
|
|
done()
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('when ignoring flush errors', function () {
|
|
|
|
it('should remove the doc from redis', function (done) {
|
|
|
|
this.DocumentManager.flushAndDeleteDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
{ ignoreFlushErrors: true },
|
2021-07-13 07:04:42 -04:00
|
|
|
error => {
|
2021-08-19 10:40:31 -04:00
|
|
|
if (error) {
|
2020-05-06 06:11:36 -04:00
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
this.RedisManager.removeDocFromMemory.called.should.equal(true)
|
2021-08-19 10:40:31 -04:00
|
|
|
done()
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('flushDocIfLoaded', function () {
|
|
|
|
describe('when the doc is in Redis', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.RedisManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.unflushedTime,
|
|
|
|
this.lastUpdatedAt,
|
|
|
|
this.lastUpdatedBy
|
|
|
|
)
|
|
|
|
this.RedisManager.clearUnflushedTime = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null)
|
|
|
|
this.PersistenceManager.setDoc = sinon.stub().yields()
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushDocIfLoaded(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc from redis', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should write the doc lines to the persistence layer', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.setDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.lastUpdatedAt,
|
|
|
|
this.lastUpdatedBy
|
|
|
|
)
|
|
|
|
.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
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should time the execution', function () {
|
|
|
|
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
|
|
|
describe('when the document is not in Redis', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.RedisManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, null, null, null)
|
|
|
|
this.PersistenceManager.setDoc = sinon.stub().yields()
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushDocIfLoaded(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc from redis', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not write anything to the persistence layer', function () {
|
|
|
|
this.PersistenceManager.setDoc.called.should.equal(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should time the execution', function () {
|
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getDocAndRecentOps', function () {
|
|
|
|
describe('with a previous version specified', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId
|
|
|
|
)
|
|
|
|
this.RedisManager.getPreviousDocOps = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, this.ops)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDocAndRecentOps(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.fromVersion,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc ops', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.getPreviousDocOps
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.doc_id, this.fromVersion, this.version)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the callback with the doc info', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ops,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should time the execution', function () {
|
|
|
|
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
|
|
|
describe('with no previous version specified', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId
|
|
|
|
)
|
|
|
|
this.RedisManager.getPreviousDocOps = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, this.ops)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDocAndRecentOps(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
-1,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not need to get the doc ops', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.getPreviousDocOps.called.should.equal(false)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the callback with the doc info', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
[],
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should time the execution', function () {
|
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getDoc', function () {
|
|
|
|
describe('when the doc exists in Redis', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.RedisManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.unflushedTime
|
|
|
|
)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc(this.project_id, this.doc_id, this.callback)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc from Redis', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the callback with the doc info', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.unflushedTime,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should time the execution', function () {
|
|
|
|
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
|
|
|
describe('when the doc does not exist in Redis', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.RedisManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, null, null, null, null, null)
|
|
|
|
this.PersistenceManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.projectHistoryType
|
|
|
|
)
|
|
|
|
this.RedisManager.putDocInMemory = sinon.stub().yields()
|
|
|
|
this.RedisManager.setHistoryType = sinon.stub().yields()
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc(this.project_id, this.doc_id, this.callback)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should try to get the doc from Redis', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc from the PersistenceManager', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should set the doc in Redis', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.putDocInMemory
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should set the history type in Redis', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.setHistoryType
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.doc_id, this.projectHistoryType)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the callback with the doc info', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId,
|
|
|
|
null,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should time the execution', function () {
|
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('setDoc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('with plain tex lines', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.beforeLines = ['before', 'lines']
|
|
|
|
this.afterLines = ['after', 'lines']
|
|
|
|
this.ops = [
|
|
|
|
{ i: 'foo', p: 4 },
|
2021-07-13 07:04:42 -04:00
|
|
|
{ d: 'bar', p: 42 },
|
2020-05-06 06:11:36 -04:00
|
|
|
]
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.beforeLines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.unflushedTime,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
this.DiffCodec.diffAsShareJsOp = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, this.ops)
|
|
|
|
this.UpdateManager.applyUpdate = sinon.stub().callsArgWith(3, null)
|
|
|
|
this.DocumentManager.flushDocIfLoaded = sinon.stub().callsArg(2)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushAndDeleteDoc = sinon.stub().callsArg(3)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('when already loaded', function () {
|
|
|
|
beforeEach(function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.setDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.afterLines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
false,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the current doc lines', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return a diff of the old and new lines', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DiffCodec.diffAsShareJsOp
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.beforeLines, this.afterLines)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should apply the diff as a ShareJS op', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.UpdateManager.applyUpdate
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id, {
|
|
|
|
doc: this.doc_id,
|
|
|
|
v: this.version,
|
|
|
|
op: this.ops,
|
|
|
|
meta: {
|
|
|
|
type: 'external',
|
|
|
|
source: this.source,
|
2021-07-13 07:04:42 -04:00
|
|
|
user_id: this.user_id,
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should flush the doc to Mongo', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushDocIfLoaded
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not flush the project history', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.HistoryManager.flushProjectChangesAsync.called.should.equal(
|
2020-05-06 06:11:36 -04:00
|
|
|
false
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should call the callback', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback.calledWith(null).should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should time the execution', function () {
|
|
|
|
this.Metrics.Timer.prototype.done.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when not already loaded', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.beforeLines,
|
|
|
|
this.version,
|
|
|
|
this.pathname,
|
|
|
|
null,
|
|
|
|
false
|
|
|
|
)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.setDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.afterLines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
false,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should flush and delete the doc from the doc updater', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushAndDeleteDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id, {})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should not flush the project history', function () {
|
|
|
|
this.HistoryManager.flushProjectChangesAsync
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWithExactly(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('without new lines', function () {
|
|
|
|
beforeEach(function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.setDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
null,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
false,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the callback with an error', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.callback.calledWith(new Error('No lines were passed to setDoc'))
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should not try to get the doc lines', function () {
|
|
|
|
this.DocumentManager.getDoc.called.should.equal(false)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('with the undoing flag', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
// Copy ops so we don't interfere with other tests
|
|
|
|
this.ops = [
|
|
|
|
{ i: 'foo', p: 4 },
|
2021-07-13 07:04:42 -04:00
|
|
|
{ d: 'bar', p: 42 },
|
2020-05-06 06:11:36 -04:00
|
|
|
]
|
|
|
|
this.DiffCodec.diffAsShareJsOp = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, this.ops)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.setDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.afterLines,
|
|
|
|
this.source,
|
|
|
|
this.user_id,
|
|
|
|
true,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should set the undo flag on each op', function () {
|
|
|
|
this.ops.map(op => op.u.should.equal(true))
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('acceptChanges', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.change_id = 'mock-change-id'
|
|
|
|
this.change_ids = [
|
|
|
|
'mock-change-id-1',
|
|
|
|
'mock-change-id-2',
|
|
|
|
'mock-change-id-3',
|
2021-07-13 07:04:42 -04:00
|
|
|
'mock-change-id-4',
|
2020-05-06 06:11:36 -04:00
|
|
|
]
|
|
|
|
this.version = 34
|
|
|
|
this.lines = ['original', 'lines']
|
|
|
|
this.ranges = { entries: 'mock', comments: 'mock' }
|
|
|
|
this.updated_ranges = { entries: 'updated', comments: 'updated' }
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, this.lines, this.version, this.ranges)
|
|
|
|
this.RangesManager.acceptChanges = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, this.updated_ranges)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.updateDocument = sinon.stub().yields()
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully with a single change', function () {
|
|
|
|
beforeEach(function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.acceptChanges(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
[this.change_id],
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should get the document's current ranges", function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should apply the accept change to the ranges', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RangesManager.acceptChanges
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith([this.change_id], this.ranges)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should save the updated ranges', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.updateDocument
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
[],
|
|
|
|
this.updated_ranges,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should call the callback', function () {
|
|
|
|
this.callback.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully with multiple changes', function () {
|
|
|
|
beforeEach(function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.acceptChanges(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.change_ids,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should apply the accept change to the ranges', function () {
|
|
|
|
this.RangesManager.acceptChanges
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.change_ids, this.ranges)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('when the doc is not found', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, null, null, null)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.acceptChanges(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
[this.change_id],
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not save anything', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.updateDocument.called.should.equal(false)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should call the callback with a not found error', function () {
|
|
|
|
this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
|
|
|
.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('deleteComment', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.comment_id = 'mock-comment-id'
|
|
|
|
this.version = 34
|
|
|
|
this.lines = ['original', 'lines']
|
|
|
|
this.ranges = { comments: ['one', 'two', 'three'] }
|
|
|
|
this.updated_ranges = { comments: ['one', 'three'] }
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, this.lines, this.version, this.ranges)
|
|
|
|
this.RangesManager.deleteComment = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, this.updated_ranges)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.updateDocument = sinon.stub().yields()
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('successfully', function () {
|
|
|
|
beforeEach(function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.deleteComment(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.comment_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should get the document's current ranges", function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should delete the comment from the ranges', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RangesManager.deleteComment
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.comment_id, this.ranges)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should save the updated ranges', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.updateDocument
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
[],
|
|
|
|
this.updated_ranges,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should call the callback', function () {
|
|
|
|
this.callback.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('when the doc is not found', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, null, null, null)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.acceptChanges(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
[this.comment_id],
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not save anything', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.updateDocument.called.should.equal(false)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should call the callback with a not found error', function () {
|
|
|
|
this.callback
|
2020-05-15 14:29:49 -04:00
|
|
|
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
|
|
|
.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getDocAndFlushIfOld', function () {
|
|
|
|
beforeEach(function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushDocIfLoaded = sinon.stub().callsArg(2)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the doc is in Redis', function () {
|
|
|
|
describe('and has changes to be flushed', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.pathname,
|
|
|
|
Date.now() - 1e9,
|
|
|
|
true
|
|
|
|
)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDocAndFlushIfOld(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should flush the doc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushDocIfLoaded
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should call the callback with the lines and versions', function () {
|
|
|
|
this.callback
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(null, this.lines, this.version)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe("and has only changes that don't need to be flushed", function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
Date.now() - 100,
|
|
|
|
true
|
|
|
|
)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDocAndFlushIfOld(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not flush the doc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushDocIfLoaded.called.should.equal(false)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should call the callback with the lines and versions', function () {
|
|
|
|
this.callback
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(null, this.lines, this.version)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('when the doc is not in Redis', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
this.DocumentManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
null,
|
|
|
|
false
|
|
|
|
)
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDocAndFlushIfOld(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should get the doc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not flush the doc', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.flushDocIfLoaded.called.should.equal(false)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should call the callback with the lines and versions', function () {
|
|
|
|
this.callback
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(null, this.lines, this.version)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('renameDoc', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.update = 'some-update'
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.renameDoc = sinon.stub().yields()
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('successfully', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.renameDoc(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.user_id,
|
|
|
|
this.update,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should rename the document', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.renameDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.user_id,
|
|
|
|
this.update,
|
|
|
|
this.projectHistoryId
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('should call the callback', function () {
|
|
|
|
this.callback.called.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('resyncDocContents', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('when doc is loaded in redis', function () {
|
|
|
|
beforeEach(function () {
|
2021-11-22 09:15:36 -05:00
|
|
|
this.pathnameFromProjectStructureUpdate = '/foo/bar.tex'
|
2020-05-06 06:11:36 -04:00
|
|
|
this.RedisManager.getDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(
|
|
|
|
2,
|
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId
|
|
|
|
)
|
|
|
|
this.ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub()
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.resyncDocContents(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
2021-11-22 09:15:36 -05:00
|
|
|
this.pathnameFromProjectStructureUpdate,
|
2020-05-06 06:11:36 -04:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('gets the doc contents from redis', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('queues a resync doc content update', function () {
|
|
|
|
this.ProjectHistoryRedisManager.queueResyncDocContent
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
2021-11-22 09:15:36 -05:00
|
|
|
this.pathnameFromProjectStructureUpdate,
|
2020-05-06 06:11:36 -04:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
describe('when doc is not loaded in redis', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
beforeEach(function () {
|
2021-11-22 09:15:36 -05:00
|
|
|
this.pathnameFromProjectStructureUpdate = '/foo/bar.tex'
|
2020-05-06 06:11:36 -04:00
|
|
|
this.RedisManager.getDoc = sinon.stub().callsArgWith(2, null)
|
|
|
|
this.PersistenceManager.getDoc = sinon
|
|
|
|
.stub()
|
2021-08-19 10:40:31 -04:00
|
|
|
.yields(
|
2020-05-06 06:11:36 -04:00
|
|
|
null,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges,
|
|
|
|
this.pathname,
|
|
|
|
this.projectHistoryId
|
|
|
|
)
|
|
|
|
this.ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub()
|
2021-08-19 10:40:31 -04:00
|
|
|
this.DocumentManager.resyncDocContents(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
2021-11-22 09:15:36 -05:00
|
|
|
this.pathnameFromProjectStructureUpdate,
|
2020-05-06 06:11:36 -04:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('tries to get the doc contents from redis', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.RedisManager.getDoc
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('gets the doc contents from web', function () {
|
2021-08-19 10:40:31 -04:00
|
|
|
this.PersistenceManager.getDoc
|
|
|
|
.calledWith(this.project_id, this.doc_id, { peek: true })
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2021-08-19 10:40:31 -04:00
|
|
|
it('queues a resync doc content update', function () {
|
|
|
|
this.ProjectHistoryRedisManager.queueResyncDocContent
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
2021-11-22 09:15:36 -05:00
|
|
|
this.pathnameFromProjectStructureUpdate,
|
2020-05-06 06:11:36 -04:00
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|