|
@@ -20,14 +20,14 @@ const modulePath = require('path').join(
|
|
|
const MockClient = require('./helpers/MockClient')
|
|
const MockClient = require('./helpers/MockClient')
|
|
|
|
|
|
|
|
describe('DocumentUpdaterController', function () {
|
|
describe('DocumentUpdaterController', function () {
|
|
|
- beforeEach(function () {
|
|
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
this.project_id = 'project-id-123'
|
|
this.project_id = 'project-id-123'
|
|
|
this.doc_id = 'doc-id-123'
|
|
this.doc_id = 'doc-id-123'
|
|
|
this.callback = sinon.stub()
|
|
this.callback = sinon.stub()
|
|
|
this.io = { mock: 'socket.io' }
|
|
this.io = { mock: 'socket.io' }
|
|
|
this.rclient = []
|
|
this.rclient = []
|
|
|
this.RoomEvents = { on: sinon.stub() }
|
|
this.RoomEvents = { on: sinon.stub() }
|
|
|
- return (this.EditorUpdatesController = SandboxedModule.require(modulePath, {
|
|
|
|
|
|
|
+ this.EditorUpdatesController = SandboxedModule.require(modulePath, {
|
|
|
requires: {
|
|
requires: {
|
|
|
'logger-sharelatex': (this.logger = {
|
|
'logger-sharelatex': (this.logger = {
|
|
|
error: sinon.stub(),
|
|
error: sinon.stub(),
|
|
@@ -46,13 +46,17 @@ describe('DocumentUpdaterController', function () {
|
|
|
pubsub: null
|
|
pubsub: null
|
|
|
}
|
|
}
|
|
|
}),
|
|
}),
|
|
|
- '@overleaf/redis-wrapper': (this.redis = {
|
|
|
|
|
- createClient: (name) => {
|
|
|
|
|
- let rclientStub
|
|
|
|
|
- this.rclient.push((rclientStub = { name }))
|
|
|
|
|
- return rclientStub
|
|
|
|
|
|
|
+ './RedisClientManager': {
|
|
|
|
|
+ createClientList: () => {
|
|
|
|
|
+ this.redis = {
|
|
|
|
|
+ createClient: (name) => {
|
|
|
|
|
+ let rclientStub
|
|
|
|
|
+ this.rclient.push((rclientStub = { name }))
|
|
|
|
|
+ return rclientStub
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }),
|
|
|
|
|
|
|
+ },
|
|
|
'./SafeJsonParse': (this.SafeJsonParse = {
|
|
'./SafeJsonParse': (this.SafeJsonParse = {
|
|
|
parse: (data, cb) => cb(null, JSON.parse(data))
|
|
parse: (data, cb) => cb(null, JSON.parse(data))
|
|
|
}),
|
|
}),
|
|
@@ -64,7 +68,8 @@ describe('DocumentUpdaterController', function () {
|
|
|
}),
|
|
}),
|
|
|
'./ChannelManager': (this.ChannelManager = {})
|
|
'./ChannelManager': (this.ChannelManager = {})
|
|
|
}
|
|
}
|
|
|
- }))
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ done()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('listenForUpdatesFromDocumentUpdater', function () {
|
|
describe('listenForUpdatesFromDocumentUpdater', function () {
|
|
@@ -78,22 +83,20 @@ describe('DocumentUpdaterController', function () {
|
|
|
this.rclient[0].on = sinon.stub()
|
|
this.rclient[0].on = sinon.stub()
|
|
|
this.rclient[1].subscribe = sinon.stub()
|
|
this.rclient[1].subscribe = sinon.stub()
|
|
|
this.rclient[1].on = sinon.stub()
|
|
this.rclient[1].on = sinon.stub()
|
|
|
- return this.EditorUpdatesController.listenForUpdatesFromDocumentUpdater()
|
|
|
|
|
|
|
+ this.EditorUpdatesController.listenForUpdatesFromDocumentUpdater()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should subscribe to the doc-updater stream', function () {
|
|
it('should subscribe to the doc-updater stream', function () {
|
|
|
- return this.rclient[0].subscribe
|
|
|
|
|
- .calledWith('applied-ops')
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
|
|
+ this.rclient[0].subscribe.calledWith('applied-ops').should.equal(true)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should register a callback to handle updates', function () {
|
|
it('should register a callback to handle updates', function () {
|
|
|
- return this.rclient[0].on.calledWith('message').should.equal(true)
|
|
|
|
|
|
|
+ this.rclient[0].on.calledWith('message').should.equal(true)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should subscribe to any additional doc-updater stream', function () {
|
|
|
|
|
|
|
+ it('should subscribe to any additional doc-updater stream', function () {
|
|
|
this.rclient[1].subscribe.calledWith('applied-ops').should.equal(true)
|
|
this.rclient[1].subscribe.calledWith('applied-ops').should.equal(true)
|
|
|
- return this.rclient[1].on.calledWith('message').should.equal(true)
|
|
|
|
|
|
|
+ this.rclient[1].on.calledWith('message').should.equal(true)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -110,7 +113,7 @@ describe('DocumentUpdaterController', function () {
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should log an error', function () {
|
|
|
|
|
|
|
+ it('should log an error', function () {
|
|
|
return this.logger.error.called.should.equal(true)
|
|
return this.logger.error.called.should.equal(true)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -129,14 +132,14 @@ describe('DocumentUpdaterController', function () {
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return it('should apply the update', function () {
|
|
|
|
|
|
|
+ it('should apply the update', function () {
|
|
|
return this.EditorUpdatesController._applyUpdateFromDocumentUpdater
|
|
return this.EditorUpdatesController._applyUpdateFromDocumentUpdater
|
|
|
.calledWith(this.io, this.doc_id, this.message.op)
|
|
.calledWith(this.io, this.doc_id, this.message.op)
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return describe('with error', function () {
|
|
|
|
|
|
|
+ describe('with error', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.message = {
|
|
this.message = {
|
|
|
doc_id: this.doc_id,
|
|
doc_id: this.doc_id,
|