2014-11-17 12:23:30 +00:00
|
|
|
RealTimeClient = require "./helpers/RealTimeClient"
|
|
|
|
MockDocUpdaterServer = require "./helpers/MockDocUpdaterServer"
|
|
|
|
FixturesManager = require "./helpers/FixturesManager"
|
|
|
|
|
|
|
|
async = require "async"
|
|
|
|
|
2014-11-14 16:51:55 +00:00
|
|
|
describe "leaveProject", ->
|
2014-11-17 12:23:30 +00:00
|
|
|
before (done) ->
|
2016-01-20 17:51:24 +00:00
|
|
|
MockDocUpdaterServer.run done
|
2014-11-17 12:23:30 +00:00
|
|
|
|
2014-11-14 16:51:55 +00:00
|
|
|
describe "with other clients in the project", ->
|
2014-11-17 12:23:30 +00:00
|
|
|
before (done) ->
|
|
|
|
async.series [
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: "owner"
|
|
|
|
project: {
|
|
|
|
name: "Test Project"
|
|
|
|
}
|
|
|
|
}, (e, {@project_id, @user_id}) => cb()
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@clientA = RealTimeClient.connect()
|
2016-12-08 11:25:25 +00:00
|
|
|
@clientA.on "connectionAccepted", cb
|
2014-11-17 12:23:30 +00:00
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@clientB = RealTimeClient.connect()
|
2016-12-08 11:25:25 +00:00
|
|
|
@clientB.on "connectionAccepted", cb
|
2014-11-17 12:23:30 +00:00
|
|
|
|
|
|
|
@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
|
2016-12-08 11:25:25 +00:00
|
|
|
setTimeout done, 1000
|
2014-11-17 12:23:30 +00:00
|
|
|
|
|
|
|
], done
|
|
|
|
|
|
|
|
it "should emit a disconnect message to the room", ->
|
|
|
|
@clientBDisconnectMessages.should.deep.equal [@clientA.socket.sessionid]
|
2014-11-14 16:51:55 +00:00
|
|
|
|
2014-11-17 12:23:30 +00:00
|
|
|
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()
|
2014-11-14 16:51:55 +00:00
|
|
|
|
2014-11-17 12:23:30 +00:00
|
|
|
it "should not flush the project to the document updater", ->
|
|
|
|
MockDocUpdaterServer.deleteProject
|
|
|
|
.calledWith(@project_id)
|
|
|
|
.should.equal false
|
2014-11-14 16:51:55 +00:00
|
|
|
|
|
|
|
describe "with no other clients in the project", ->
|
2014-11-17 12:23:30 +00:00
|
|
|
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
|
2016-12-08 11:25:25 +00:00
|
|
|
setTimeout done, 1000
|
2014-11-17 12:23:30 +00:00
|
|
|
], done
|
|
|
|
|
|
|
|
it "should flush the project to the document updater", ->
|
|
|
|
MockDocUpdaterServer.deleteProject
|
|
|
|
.calledWith(@project_id)
|
|
|
|
.should.equal true
|