2014-11-07 12:38:12 -05:00
|
|
|
chai = require("chai")
|
|
|
|
expect = chai.expect
|
|
|
|
|
|
|
|
RealTimeClient = require "./helpers/RealTimeClient"
|
|
|
|
|
|
|
|
describe "Session", ->
|
|
|
|
describe "with an established session", ->
|
2014-11-13 06:48:49 -05:00
|
|
|
before (done) ->
|
2014-11-10 06:27:08 -05:00
|
|
|
@user_id = "mock-user-id"
|
2014-11-07 12:38:12 -05:00
|
|
|
RealTimeClient.setSession {
|
|
|
|
user: { _id: @user_id }
|
|
|
|
}, (error) =>
|
|
|
|
throw error if error?
|
|
|
|
@client = RealTimeClient.connect()
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should not get disconnected", (done) ->
|
|
|
|
disconnected = false
|
|
|
|
@client.on "disconnect", () ->
|
|
|
|
disconnected = true
|
|
|
|
setTimeout () =>
|
|
|
|
expect(disconnected).to.equal false
|
|
|
|
done()
|
|
|
|
, 500
|
2014-11-13 06:48:49 -05:00
|
|
|
|
|
|
|
it "should appear in the list of connected clients", (done) ->
|
|
|
|
RealTimeClient.getConnectedClients (error, clients) =>
|
|
|
|
included = false
|
|
|
|
for client in clients
|
|
|
|
if client.client_id == @client.socket.sessionid
|
|
|
|
included = true
|
|
|
|
break
|
|
|
|
expect(included).to.equal true
|
|
|
|
done()
|
2014-11-07 12:38:12 -05:00
|
|
|
|
|
|
|
describe "without an established session", ->
|
2014-11-13 06:48:49 -05:00
|
|
|
before (done) ->
|
2014-11-07 12:38:12 -05:00
|
|
|
RealTimeClient.unsetSession (error) =>
|
|
|
|
throw error if error?
|
|
|
|
@client = RealTimeClient.connect()
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should get disconnected", (done) ->
|
|
|
|
@client.on "disconnect", () ->
|
|
|
|
done()
|
|
|
|
|
2014-11-13 06:48:49 -05:00
|
|
|
it "not should appear in the list of connected clients", (done) ->
|
|
|
|
RealTimeClient.getConnectedClients (error, clients) =>
|
|
|
|
included = false
|
|
|
|
for client in clients
|
|
|
|
if client.client_id == @client.socket.sessionid
|
|
|
|
included = true
|
|
|
|
break
|
|
|
|
expect(included).to.equal false
|
|
|
|
done()
|
|
|
|
|
2014-11-10 06:27:08 -05:00
|
|
|
describe "without a valid user set on the session", ->
|
2014-11-13 06:48:49 -05:00
|
|
|
before (done) ->
|
2014-11-07 12:38:12 -05:00
|
|
|
RealTimeClient.setSession {
|
|
|
|
foo: "bar"
|
|
|
|
}, (error) =>
|
|
|
|
throw error if error?
|
|
|
|
@client = RealTimeClient.connect()
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should get disconnected", (done) ->
|
|
|
|
@client.on "disconnect", () ->
|
2014-11-13 06:48:49 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it "not should appear in the list of connected clients", (done) ->
|
|
|
|
RealTimeClient.getConnectedClients (error, clients) =>
|
|
|
|
included = false
|
|
|
|
for client in clients
|
|
|
|
if client.client_id == @client.socket.sessionid
|
|
|
|
included = true
|
|
|
|
break
|
|
|
|
expect(included).to.equal false
|
2014-11-07 12:38:12 -05:00
|
|
|
done()
|