2014-11-10 06:27:08 -05:00
|
|
|
chai = require("chai")
|
|
|
|
expect = chai.expect
|
|
|
|
chai.should()
|
|
|
|
|
|
|
|
RealTimeClient = require "./helpers/RealTimeClient"
|
2014-11-12 10:54:55 -05:00
|
|
|
MockWebServer = require "./helpers/MockWebServer"
|
|
|
|
FixturesManager = require "./helpers/FixturesManager"
|
|
|
|
|
2014-11-10 06:27:08 -05:00
|
|
|
|
|
|
|
describe "joinProject", ->
|
2014-11-10 06:38:26 -05:00
|
|
|
describe "when authorized", ->
|
|
|
|
before (done) ->
|
2014-11-12 10:54:55 -05:00
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: "owner"
|
|
|
|
project: {
|
|
|
|
name: "Test Project"
|
|
|
|
}
|
|
|
|
}, (error, data) =>
|
2014-11-10 06:27:08 -05:00
|
|
|
throw error if error?
|
2014-11-12 10:54:55 -05:00
|
|
|
{@user_id, @project_id} = data
|
|
|
|
@client = RealTimeClient.connect()
|
|
|
|
@client.emit "joinProject", {
|
|
|
|
project_id: @project_id
|
|
|
|
}, (error, @project, @privilegeLevel, @protocolVersion) =>
|
2014-11-10 06:27:08 -05:00
|
|
|
throw error if error?
|
2014-11-12 10:54:55 -05:00
|
|
|
done()
|
2014-11-10 06:38:26 -05:00
|
|
|
|
|
|
|
it "should get the project from web", ->
|
2014-11-12 10:54:55 -05:00
|
|
|
MockWebServer.joinProject
|
2014-11-10 06:38:26 -05:00
|
|
|
.calledWith(@project_id, @user_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return the project", ->
|
|
|
|
@project.should.deep.equal {
|
|
|
|
name: "Test Project"
|
|
|
|
}
|
|
|
|
|
|
|
|
it "should return the privilege level", ->
|
|
|
|
@privilegeLevel.should.equal "owner"
|
|
|
|
|
|
|
|
it "should return the protocolVersion", ->
|
|
|
|
@protocolVersion.should.equal 2
|
|
|
|
|
2014-11-13 06:48:49 -05:00
|
|
|
it "should have joined the project room", (done) ->
|
|
|
|
RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
|
|
|
|
expect(@project_id in client.rooms).to.equal true
|
|
|
|
done()
|
2014-11-13 08:05:49 -05:00
|
|
|
|
|
|
|
it "should have marked the user as connected", (done) ->
|
|
|
|
@client.emit "getConnectedUsers", (error, users) =>
|
|
|
|
connected = false
|
|
|
|
for user in users
|
|
|
|
if user.client_id == @client.socket.sessionid and user.user_id == @user_id
|
|
|
|
connected = true
|
|
|
|
break
|
|
|
|
expect(connected).to.equal true
|
|
|
|
done()
|
2014-11-13 06:48:49 -05:00
|
|
|
|
2014-11-10 06:38:26 -05:00
|
|
|
describe "when not authorized", ->
|
|
|
|
before (done) ->
|
2014-11-12 10:54:55 -05:00
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: null
|
|
|
|
project: {
|
|
|
|
name: "Test Project"
|
|
|
|
}
|
|
|
|
}, (error, data) =>
|
2014-11-10 06:38:26 -05:00
|
|
|
throw error if error?
|
2014-11-12 10:54:55 -05:00
|
|
|
{@user_id, @project_id} = data
|
|
|
|
@client = RealTimeClient.connect()
|
|
|
|
@client.emit "joinProject", {
|
|
|
|
project_id: @project_id
|
|
|
|
}, (@error, @project, @privilegeLevel, @protocolVersion) =>
|
|
|
|
done()
|
2014-11-10 06:38:26 -05:00
|
|
|
|
|
|
|
it "should return an error", ->
|
2014-11-12 10:54:55 -05:00
|
|
|
# We don't return specific errors
|
|
|
|
@error.message.should.equal "Something went wrong"
|
2014-11-13 06:48:49 -05:00
|
|
|
|
|
|
|
it "should not have joined the project room", (done) ->
|
|
|
|
RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
|
|
|
|
expect(@project_id in client.rooms).to.equal false
|
|
|
|
done()
|