2014-11-17 07:23:30 -05:00
|
|
|
RealTimeClient = require "./helpers/RealTimeClient"
|
|
|
|
MockDocUpdaterServer = require "./helpers/MockDocUpdaterServer"
|
|
|
|
FixturesManager = require "./helpers/FixturesManager"
|
|
|
|
|
|
|
|
async = require "async"
|
|
|
|
|
2020-05-15 05:43:11 -04:00
|
|
|
settings = require "settings-sharelatex"
|
|
|
|
redis = require "redis-sharelatex"
|
|
|
|
rclient = redis.createClient(settings.redis.pubsub)
|
|
|
|
|
2014-11-14 11:51:55 -05:00
|
|
|
describe "leaveProject", ->
|
2014-11-17 07:23:30 -05:00
|
|
|
before (done) ->
|
2016-01-20 12:51:24 -05:00
|
|
|
MockDocUpdaterServer.run done
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-14 11:51:55 -05:00
|
|
|
describe "with other clients in the project", ->
|
2014-11-17 07:23:30 -05:00
|
|
|
before (done) ->
|
|
|
|
async.series [
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: "owner"
|
|
|
|
project: {
|
|
|
|
name: "Test Project"
|
|
|
|
}
|
|
|
|
}, (e, {@project_id, @user_id}) => cb()
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
@clientA = RealTimeClient.connect()
|
2016-12-08 06:25:25 -05:00
|
|
|
@clientA.on "connectionAccepted", cb
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
@clientB = RealTimeClient.connect()
|
2016-12-08 06:25:25 -05:00
|
|
|
@clientB.on "connectionAccepted", cb
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
@clientBDisconnectMessages = []
|
|
|
|
@clientB.on "clientTracking.clientDisconnected", (data) =>
|
|
|
|
@clientBDisconnectMessages.push data
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
@clientA.emit "joinProject", project_id: @project_id, (error, @project, @privilegeLevel, @protocolVersion) =>
|
|
|
|
cb(error)
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
@clientB.emit "joinProject", project_id: @project_id, (error, @project, @privilegeLevel, @protocolVersion) =>
|
|
|
|
cb(error)
|
2020-05-15 05:43:11 -04:00
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
|
|
|
|
cb(e)
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@clientA.emit "joinDoc", @doc_id, cb
|
|
|
|
(cb) =>
|
|
|
|
@clientB.emit "joinDoc", @doc_id, cb
|
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
# leaveProject is called when the client disconnects
|
|
|
|
@clientA.on "disconnect", () -> cb()
|
|
|
|
@clientA.disconnect()
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
# The API waits a little while before flushing changes
|
2016-12-08 06:25:25 -05:00
|
|
|
setTimeout done, 1000
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
], done
|
|
|
|
|
|
|
|
it "should emit a disconnect message to the room", ->
|
2020-06-04 10:52:13 -04:00
|
|
|
@clientBDisconnectMessages.should.deep.equal [@clientA.publicId]
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
it "should no longer list the client in connected users", (done) ->
|
|
|
|
@clientB.emit "clientTracking.getConnectedUsers", (error, users) =>
|
|
|
|
for user in users
|
2020-06-04 10:52:13 -04:00
|
|
|
if user.client_id == @clientA.publicId
|
2014-11-17 07:23:30 -05:00
|
|
|
throw "Expected clientA to not be listed in connected users"
|
|
|
|
return done()
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
it "should not flush the project to the document updater", ->
|
|
|
|
MockDocUpdaterServer.deleteProject
|
|
|
|
.calledWith(@project_id)
|
|
|
|
.should.equal false
|
2014-11-14 11:51:55 -05:00
|
|
|
|
2020-05-15 05:43:11 -04:00
|
|
|
it "should remain subscribed to the editor-events channels", (done) ->
|
|
|
|
rclient.pubsub 'CHANNELS', (err, resp) =>
|
|
|
|
return done(err) if err
|
|
|
|
resp.should.include "editor-events:#{@project_id}"
|
|
|
|
done()
|
|
|
|
return null
|
|
|
|
|
|
|
|
it "should remain subscribed to the applied-ops channels", (done) ->
|
|
|
|
rclient.pubsub 'CHANNELS', (err, resp) =>
|
|
|
|
return done(err) if err
|
|
|
|
resp.should.include "applied-ops:#{@doc_id}"
|
|
|
|
done()
|
|
|
|
return null
|
|
|
|
|
2014-11-14 11:51:55 -05:00
|
|
|
describe "with no other clients in the project", ->
|
2014-11-17 07:23:30 -05:00
|
|
|
before (done) ->
|
|
|
|
async.series [
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: "owner"
|
|
|
|
project: {
|
|
|
|
name: "Test Project"
|
|
|
|
}
|
|
|
|
}, (e, {@project_id, @user_id}) => cb()
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
@clientA = RealTimeClient.connect()
|
|
|
|
@clientA.on "connect", cb
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
@clientA.emit "joinProject", project_id: @project_id, (error, @project, @privilegeLevel, @protocolVersion) =>
|
|
|
|
cb(error)
|
2020-05-15 05:43:11 -04:00
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
|
|
|
|
cb(e)
|
|
|
|
(cb) =>
|
|
|
|
@clientA.emit "joinDoc", @doc_id, cb
|
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
# leaveProject is called when the client disconnects
|
|
|
|
@clientA.on "disconnect", () -> cb()
|
|
|
|
@clientA.disconnect()
|
2020-05-15 05:43:11 -04:00
|
|
|
|
2014-11-17 07:23:30 -05:00
|
|
|
(cb) =>
|
|
|
|
# The API waits a little while before flushing changes
|
2016-12-08 06:25:25 -05:00
|
|
|
setTimeout done, 1000
|
2014-11-17 07:23:30 -05:00
|
|
|
], done
|
|
|
|
|
|
|
|
it "should flush the project to the document updater", ->
|
|
|
|
MockDocUpdaterServer.deleteProject
|
|
|
|
.calledWith(@project_id)
|
|
|
|
.should.equal true
|
2020-05-15 05:43:11 -04:00
|
|
|
|
|
|
|
it "should not subscribe to the editor-events channels anymore", (done) ->
|
|
|
|
rclient.pubsub 'CHANNELS', (err, resp) =>
|
|
|
|
return done(err) if err
|
|
|
|
resp.should.not.include "editor-events:#{@project_id}"
|
|
|
|
done()
|
|
|
|
return null
|
|
|
|
|
|
|
|
it "should not subscribe to the applied-ops channels anymore", (done) ->
|
|
|
|
rclient.pubsub 'CHANNELS', (err, resp) =>
|
|
|
|
return done(err) if err
|
|
|
|
resp.should.not.include "applied-ops:#{@doc_id}"
|
|
|
|
done()
|
|
|
|
return null
|