mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 18:53:44 -05:00
114 lines
No EOL
3.4 KiB
CoffeeScript
114 lines
No EOL
3.4 KiB
CoffeeScript
RealTimeClient = require "./helpers/RealTimeClient"
|
|
MockDocUpdaterServer = require "./helpers/MockDocUpdaterServer"
|
|
MockTrackChangesServer = require "./helpers/MockTrackChangesServer"
|
|
FixturesManager = require "./helpers/FixturesManager"
|
|
|
|
async = require "async"
|
|
|
|
describe "leaveProject", ->
|
|
before (done) ->
|
|
MockDocUpdaterServer.run (error) ->
|
|
return done(error) if error?
|
|
MockTrackChangesServer.run done
|
|
|
|
describe "with other clients in the project", ->
|
|
before (done) ->
|
|
async.series [
|
|
(cb) =>
|
|
FixturesManager.setUpProject {
|
|
privilegeLevel: "owner"
|
|
project: {
|
|
name: "Test Project"
|
|
}
|
|
}, (e, {@project_id, @user_id}) => cb()
|
|
|
|
(cb) =>
|
|
@clientA = RealTimeClient.connect()
|
|
@clientA.on "connect", cb
|
|
|
|
(cb) =>
|
|
@clientB = RealTimeClient.connect()
|
|
@clientB.on "connect", cb
|
|
|
|
@clientBDisconnectMessages = []
|
|
@clientB.on "clientTracking.clientDisconnected", (data) =>
|
|
@clientBDisconnectMessages.push data
|
|
|
|
(cb) =>
|
|
@clientA.emit "joinProject", project_id: @project_id, (error, @project, @privilegeLevel, @protocolVersion) =>
|
|
cb(error)
|
|
|
|
(cb) =>
|
|
@clientB.emit "joinProject", project_id: @project_id, (error, @project, @privilegeLevel, @protocolVersion) =>
|
|
cb(error)
|
|
|
|
(cb) =>
|
|
# leaveProject is called when the client disconnects
|
|
@clientA.on "disconnect", () -> cb()
|
|
@clientA.disconnect()
|
|
|
|
(cb) =>
|
|
# The API waits a little while before flushing changes
|
|
setTimeout done, require("../../../app/js/WebsocketController").FLUSH_IF_EMPTY_DELAY * 2
|
|
|
|
], done
|
|
|
|
it "should emit a disconnect message to the room", ->
|
|
@clientBDisconnectMessages.should.deep.equal [@clientA.socket.sessionid]
|
|
|
|
it "should no longer list the client in connected users", (done) ->
|
|
@clientB.emit "clientTracking.getConnectedUsers", (error, users) =>
|
|
for user in users
|
|
if user.client_id == @clientA.socket.sessionid
|
|
throw "Expected clientA to not be listed in connected users"
|
|
return done()
|
|
|
|
it "should not flush the project to the document updater", ->
|
|
MockDocUpdaterServer.deleteProject
|
|
.calledWith(@project_id)
|
|
.should.equal false
|
|
|
|
it "should not flush the project in track changes", ->
|
|
MockTrackChangesServer.flushProject
|
|
.calledWith(@project_id)
|
|
.should.equal false
|
|
|
|
describe "with no other clients in the project", ->
|
|
before (done) ->
|
|
async.series [
|
|
(cb) =>
|
|
FixturesManager.setUpProject {
|
|
privilegeLevel: "owner"
|
|
project: {
|
|
name: "Test Project"
|
|
}
|
|
}, (e, {@project_id, @user_id}) => cb()
|
|
|
|
(cb) =>
|
|
@clientA = RealTimeClient.connect()
|
|
@clientA.on "connect", cb
|
|
|
|
(cb) =>
|
|
@clientA.emit "joinProject", project_id: @project_id, (error, @project, @privilegeLevel, @protocolVersion) =>
|
|
cb(error)
|
|
|
|
(cb) =>
|
|
# leaveProject is called when the client disconnects
|
|
@clientA.on "disconnect", () -> cb()
|
|
@clientA.disconnect()
|
|
|
|
(cb) =>
|
|
# The API waits a little while before flushing changes
|
|
setTimeout done, require("../../../app/js/WebsocketController").FLUSH_IF_EMPTY_DELAY * 2
|
|
], done
|
|
|
|
it "should flush the project to the document updater", ->
|
|
MockDocUpdaterServer.deleteProject
|
|
.calledWith(@project_id)
|
|
.should.equal true
|
|
|
|
it "should flush the project in track changes", ->
|
|
MockTrackChangesServer.flushProject
|
|
.calledWith(@project_id)
|
|
.should.equal true
|
|
|