2014-11-10 11:27:08 +00:00
|
|
|
chai = require("chai")
|
|
|
|
expect = chai.expect
|
|
|
|
chai.should()
|
|
|
|
|
|
|
|
RealTimeClient = require "./helpers/RealTimeClient"
|
2014-11-12 15:54:55 +00:00
|
|
|
MockWebServer = require "./helpers/MockWebServer"
|
|
|
|
FixturesManager = require "./helpers/FixturesManager"
|
|
|
|
|
2014-11-14 10:21:54 +00:00
|
|
|
async = require "async"
|
2014-11-10 11:27:08 +00:00
|
|
|
|
|
|
|
describe "joinProject", ->
|
2014-11-10 11:38:26 +00:00
|
|
|
describe "when authorized", ->
|
|
|
|
before (done) ->
|
2014-11-14 10:21:54 +00:00
|
|
|
async.series [
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: "owner"
|
|
|
|
project: {
|
|
|
|
name: "Test Project"
|
|
|
|
}
|
|
|
|
}, (e, {@project_id, @user_id}) =>
|
|
|
|
cb(e)
|
2016-12-08 11:25:25 +00:00
|
|
|
|
2014-11-14 10:21:54 +00:00
|
|
|
(cb) =>
|
|
|
|
@client = RealTimeClient.connect()
|
2016-12-08 11:25:25 +00:00
|
|
|
@client.on "connectionAccepted", cb
|
2014-11-14 10:21:54 +00:00
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "joinProject", project_id: @project_id, (error, @project, @privilegeLevel, @protocolVersion) =>
|
|
|
|
cb(error)
|
|
|
|
], done
|
2014-11-10 11:38:26 +00:00
|
|
|
|
|
|
|
it "should get the project from web", ->
|
2014-11-12 15:54:55 +00:00
|
|
|
MockWebServer.joinProject
|
2014-11-10 11:38:26 +00: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 11:48:49 +00: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 13:05:49 +00:00
|
|
|
|
|
|
|
it "should have marked the user as connected", (done) ->
|
2014-11-13 15:27:18 +00:00
|
|
|
@client.emit "clientTracking.getConnectedUsers", (error, users) =>
|
2014-11-13 13:05:49 +00:00
|
|
|
connected = false
|
|
|
|
for user in users
|
2020-06-04 14:52:13 +00:00
|
|
|
if user.client_id == @client.publicId and user.user_id == @user_id
|
2014-11-13 13:05:49 +00:00
|
|
|
connected = true
|
|
|
|
break
|
|
|
|
expect(connected).to.equal true
|
|
|
|
done()
|
2014-11-13 11:48:49 +00:00
|
|
|
|
2014-11-10 11:38:26 +00:00
|
|
|
describe "when not authorized", ->
|
|
|
|
before (done) ->
|
2014-11-14 10:21:54 +00:00
|
|
|
async.series [
|
|
|
|
(cb) =>
|
|
|
|
FixturesManager.setUpProject {
|
|
|
|
privilegeLevel: null
|
|
|
|
project: {
|
|
|
|
name: "Test Project"
|
|
|
|
}
|
|
|
|
}, (e, {@project_id, @user_id}) =>
|
|
|
|
cb(e)
|
2016-12-08 11:25:25 +00:00
|
|
|
|
2014-11-14 10:21:54 +00:00
|
|
|
(cb) =>
|
|
|
|
@client = RealTimeClient.connect()
|
2016-12-08 11:25:25 +00:00
|
|
|
@client.on "connectionAccepted", cb
|
2014-11-14 10:21:54 +00:00
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "joinProject", project_id: @project_id, (@error, @project, @privilegeLevel, @protocolVersion) =>
|
|
|
|
cb()
|
|
|
|
], done
|
2014-11-10 11:38:26 +00:00
|
|
|
|
|
|
|
it "should return an error", ->
|
2016-12-08 11:12:07 +00:00
|
|
|
@error.message.should.equal "not authorized"
|
2014-11-13 11:48:49 +00: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()
|
2019-08-31 13:04:36 +00:00
|
|
|
|
|
|
|
describe "when over rate limit", ->
|
|
|
|
before (done) ->
|
|
|
|
async.series [
|
|
|
|
(cb) =>
|
|
|
|
@client = RealTimeClient.connect()
|
|
|
|
@client.on "connectionAccepted", cb
|
|
|
|
|
|
|
|
(cb) =>
|
|
|
|
@client.emit "joinProject", project_id: 'rate-limited', (@error) =>
|
|
|
|
cb()
|
|
|
|
], done
|
|
|
|
|
|
|
|
it "should return a TooManyRequests error code", ->
|
|
|
|
@error.message.should.equal "rate-limit hit when joining project"
|
|
|
|
@error.code.should.equal "TooManyRequests"
|
|
|
|
|